A blog probably of interest only to nerds by John Morton.

12Dec2016

Craft CMS: A big­ger Plain Text” field.

I inher­it­ed a Craft CMS site that I now main­tain for a new client. When you inher­it oth­er people’s code, you need to see the project from their POV to get an under­stand­ing of they see things work­ing. Luck­i­ly Craft seems to encour­age log­i­cal struc­tures being built so I’ve not had too much trou­ble get­ting up to speed on this site.

One of the prob­lems I did run into was with a sim­ple Plain Text field. This client authors HTML emails in some pro­gram that gen­er­ates HTML code that then gets past­ed into a sin­gle Plain Text field in Craft. This process has worked for them so I hadn’t inves­ti­gat­ed that part of the site much yet. 

On their lat­est newslet­ter though, the text in the Plain Text field was get­ting trun­cat­ed after they tried to save the entry. 

It turned out to be the MySQL data­base itself doing to trun­cat­ing of the HTML code. If you don’t spec­i­fy a max­i­mum length to a plain text field when you cre­ate it the Craft con­trol pan­el will not lim­it the user from enter­ing any amount of text but the data­base will do it anyway.

What hap­pens is that the col­umn that gets cre­at­ed in the MySQL data­base is a text” field which will lim­it the con­tent to 64K, rough­ly 64,000 char­ac­ters. Any con­tent that is longer than that just gets dropped off the end. That’s what was hap­pen­ing to my client.

To rem­e­dy this, just go into the field cre­ation page in the Craft con­trol pan­el and give the text field a max­i­mum length greater than the 64,000 lim­it. I put in 90,000 char­ac­ters and Craft updat­ed the table to a medi­um­text” col­umn which can store 14 megabytes of text which is plen­ty of room to hold the long HTML con­tent the client was creating.