View Full Version : user hits "enter" on form, form display on next page newline?

12-13-2007, 05:17 PM
If I make a textarea in a form, and the user is filling it out and uses the carriage return to go to the next line, when they submit the form the carriage return is replaced with a single space.

Is there something I can put either on the form coding or on the second page that will make the carriage returns show as a new line on the rendered form?

It is in re: this post (http://www.dynamicdrive.com/forums/showthread.php?p=121638#post121638)

Thanks guys.

12-13-2007, 06:41 PM
Look in nl2br (http://php.net/nl2br).

Hope this helps.

12-13-2007, 07:07 PM
Or better, provide a markup language like Markdown so that the user can format it appropriately.

12-13-2007, 08:47 PM
I already tried nl2br, and it didn't work for me. I probably did it wrong, but I got parse errors on the 2nd page.

As is obvious, this isn't for me, I don't have a need for it right now other than finishing that script, but it may come in handy someday.

If I have this on the first page of the form:

<textarea name=Whatever rows=12 cols=50></textarea>

and I have this on the second:

<?php echo $_POST["Whatever"]; ?>

where would I use the nl2br()? I have tried in the declaration of "whatever" I have tried making each $_POST... a string with it in header declaration, on the first page, on the second page...

Nothing worked.

12-13-2007, 08:59 PM
You would use it like so:

<?php echo nl2br($_POST['Whatever']); ?>

Hope this helps.

12-15-2007, 02:53 PM
I tried that and got header errors.. maybe I didn't completely remove something. I will try it again...

Thanks TS

That was it.. I had the closing paren in the wrong side of the semi-colon. DUH!

Got it right, updated the script. All is well. Thanks again.