TEXTAREAFORMAT function and custom tag

Ever needed to display data from a TEXTAREA field, preserving the line breaks, tabs, and spaces? Perhaps you want to show a confirmation page after a form submission, or you just want to show data from a database where the textarea data was stored in a column. The TextAreaFormat UDF and custom tag are the best solution to the many problems of simpler options like paragraphformat() or pre tags.

The Problem: Whitespace and line breaks lost

Ever noticed that the data doesn't look like what the user entered? If they hit the enter key while entering data to create a blank line(s), they appear to be lost when you display the data because HTML ignores white space and carriage returns. If they entered tabs or spaces, those seem "lost", too. It's not that the white space is really gone, just that HTML ignores it, and CFML doesn't help as much as it could.

You need to format that data for output in HTML.

Of course, you could wrap the output in <pre> tags, but that uses a courier-style font and worse it does not wrap long lines. You could also choose to show the data by displaying it within another textarea field, but that's limiting.

You may also know to use the CFML function paragraphformat(), which will convert 2 carriage returns into the appropriate <p> tag for display of a blank line. But what if the user hit enter only once to create just a line break? Paragraphformat won't render the <br> tag. And if they entered any consecutive spaces, those are lost (because the browser ignores them). And if they happened to copy into that textarea some code created elsewhere where they could use the tab key, that won't be rendered either by paragraphformat().

The Solution: TextAreaFormat

The TEXTAREAFORMAT custom tag or User Defined Function solves those problems. It goes several steps further than ParagraphFormat, to try to accurately render data entered in a TextArea field. Single line breaks are turned into <br> tags, double line breaks are turned into <p> tags, tab characters are turned into 8 non-breaking spaces (<nbsp), and any 3 consecutive spaces are also turned into non-breaking spaces (<nbsp).

These added features should cause display of text which has been entered within a TEXTAREA field to be accurately reproduced within a CFOUTPUT.

Please see the "example" link below for complete details, syntax, usage, and an example. These will be very helpful in understanding how, where, and why to use the tag or UDF.

<Help>
<Syntax>
<Example>
<Download>

If you have any questions, please send them to [email protected].

Further details available for:

| Home | ColdFusion | Articles | Presentations
| User Groups | Other Resources | Press Releases | Company

© 1998-2017, Charles Arehart, SysteManage
Our Practice Makes You Perfect