tags:

views:

41

answers:

3

I have a form where a user types paragraphs into a text area and then it takes them to another page after they submit. How can I pass whatever they typed to the page after they submit? The text area might have linebreaks and if I use a query string to pass the data, it gives me an error. This is my current code to pass the field:

<?php
        if(isset($_POST['form']))
    {
    $title = $_POST['title'];
    $body = $_POST['body'];
    header("SubmitForm.php?title=$title&body=$body");
    ?>
    <html>
    ...html form...

It doesn't work when the text area has line breaks in it. Thanks for the help.

A: 

You really shouldn't be putting anything that long in a query string in the first place. Look into using sessions to store data across pages instead. (This is assuming I understood the question right)

jay.lee
+1  A: 

I would suggest installing a wysiwyg editor to make this easier for you, but i assume that would add some time for the learning curve.

The simplest tips I can give you is to set a CSS attribute for your textarea: white-space:pre so that when it gets submitted, all line breaks get sent as well. On your server side, you would need to use the nl2br() function, so that when it gets saved on your DB or wherever you store them, all line breaks are converted to HTML breaks.

For your additional reference, I had a similar question like this last year.

lock
You might want to url encode the data prior to sending it across the URL.
Russell Dias
+1 for stating something i forgot :P
lock
Thanks... it put in the linebreak fine, but I have this in my css file :text-indent: 3em; , but the linebreak isnt indenting. Anything I can do about that? Thanks for the help
Preston
or is there a way to indent the text in the field whenever the user hits enter?
Preston
text-indent would only work at the beggining of each <p> tag. As mentioned above, a wysiwyg editor such as tinyMCE automatically generates new <p> tags for each newline so that would much help you instead of reinvinting the wheel.
lock
allright thanks i got it working with tinyMCE!
Preston
A: 

urlencode the data in order to pass it via query string.

Andrew67