Multiline text areas

raj12ad 25 Jun, 2008
Hi,

I'm having problems formatting text areas so that when an email is sent, it preserves line breaks / paragraphs breaks. I've come across this previous topic, but I can't seem to get it to work.

At the moment, I've got a textarea called 'message'. When we have a query through our website, if anyone puts linebreaks/paragraph breaks into the text area box, all their text gets formatted into one long line.

I've looked at the various options suggested (hacking chronoconfig.php etc.) but can't seem to get anything working.

The best option seemed to be inserting:

<?php $_POST['Message'] = str_replace("\n","<br />",$_POST['Message']); ?>



in the 'On Submit Code - before sending email' box, but this didn't work.

Any help would be most gratefully received! [file name=Messaging.cfbak size=3709]http://www.chronoengine.com/images/fbfiles/files/Messaging.cfbak[/file]
GreyHead 25 Jun, 2008
Hi raj12ad,

Search the forums for 'nl2br' that's the php function to use - you'll find several examples (some of the old code postings are still broken though).

Bob
raj12ad 26 Jun, 2008
After hunting through the board, I did find a few suggestions, but in the end I found this very simple bit of php which seems to work:

This is a snippet from my Form HTML:

<label><br />
Your message:</label>
<br /><textarea cols="80" rows="15" class="text_area" id="message" name="Message">
</textarea>



And in my Email template:

<p>From: {Name} / {Email} </p>
<p>Sent to: {Recipient} </p>
<p>Date: <?php echo date("d/m/y H:i:s", time());?><br />
---</p>
<p> </p>
<?php
print nl2br($_POST['Message']);
?>
<p></p>



It's a very simple email template, but it inserts a timestamp, and also formats the textarea, 'Message', so that any paragraph breaks the user entered on the form are reinserted. I'm sure there's a more elegant solution (I'm not saving my results into a database - just sending to an email address).

Hope this helps someone!
GreyHead 26 Jun, 2008
Hi raj12ad,

Excellent, a very nice solution.

Bob
This topic is locked and no more replies can be posted.