Preserve White-Space and Line Breaks in a Textarea

[FONT=“Georgia”]Hi there.

Not too sure if this should be in this forum or in the (X)HTML section. Feel free to move it if you’d like.

Here’s my question…

I have a contact form that uses a <textarea> for viewers to type their messages. When the form is submitted, all the text in the textarea reaches me as one long string of characters, with all the viewer’s indents and line breaks ignored.

Is there a way to preserve this white space so that the form would be more legible when it reaches me??[/FONT]

use <pre> tags when displaying. you can restyle it if needed.

otherwise, you will need to use nl2br() and then str_replace() tabs and spaces with  

Nah, they’re all still there. You’re just losing them when you redisplay as HTML isn’t whitespace sensitive. Do as clamcrusher said if you want it to look the same outside a textbox as it did inside. If you were to simply redisplay the input in a textbox you’d see the spacing is still there.

Also, don’t forget to do htmlspecialchars() so some of the user input is not intepreted incorrectly.

Many thanks. It worked. :tup: