coldfusiontextareanewline

How to replace CR+LF with <br />?


For example:

A user submits a form with a <textarea name="mytext" cols="35" rows="2"></textarea> and presses ENTER within it. How would I replace the CR-LF with a <br />?


Solution

  • CF has a function for this called ParagraphFormat():

    <cfset form.userText = paragraphFormat(form.usertext)/>
    

    From the help docs -

    Replaces characters in a string:

    It may do more than you want in that it also looks for double line breaks and adds <p> and </p> tags.

    Ben also has an enhanced version (a UDF) called paragraph2 that would be easy to modify to get the exact affect you want. Here's the link:

    http://www.cflib.org/udf/ParagraphFormat2