Log in

View Full Version : Passing Textarea data with multilines to another page



rhardo
04-12-2008, 02:57 AM
Hi guys,

I'm new to php. And i think my problem is really simple. But I could not find a solution for it. Like I said, I'm a php newbie.
So my problem is dealing with data with multilines. Supposedly, the field value will be passed to another page through a variable. If it's a single line, then no problem. But if there are line breaks, it returns an error: Warning: Header may not contain more than a single header, new line detected

Please help, thanks.

fileserverdirect
04-12-2008, 03:34 AM
Please post your php script so we can look at it and get out any errors.
This may be very easy to fix. Please also provide a link (if it is online) to see if we get the same problem.
Thanks,

rhardo
04-12-2008, 03:44 AM
Sorry, but i am not allowed to post the codes but below is the key areas that i think causing problems...

This is where the value of the text area is being processed

$F8 = POST_VARS["field8"];
header("Location: go.php?field8=$F8");

The text area...


<textarea name="field8" cols="38" wrap="physical" style="width: 85%; height: 50px;">
</textarea>

fileserverdirect
04-12-2008, 08:19 PM
This is happening because you can only have one line in though GET. If you are using this script on the same page as your form, use POST:


<form action="go.php" method="post">
...

then on go.php


<?
$feild8 = $_POST['feild8'];
//with "feild8"(inside $_POST) is the name of the textarea
?>

You could also use $_SESSION, but thats somting a little to much for what you are tring to do.

fileserverdirect
04-17-2008, 01:14 AM
Did you try my example?

boogyman
04-17-2008, 01:48 PM
submitting form information should not be done with the GET method as fileserverdirect states, and to keep the newlines entered into a textarea input box, use the nl2br() (http://us2.php.net/nl2br) function for php

fileserverdirect
04-17-2008, 10:28 PM
boogyman:
nl2br(); replaces new lines with HTML tag <br>. If there is any database interaction, form mailing, etc., the varable would look like this: $field8 = "Hello<br>this is a new line<br>Hello again, another line here";
If s/he was echoing out this variable, then it could be O.K., but if it's used in a script, it will mess up every thing. S/He could however use eregi_replace();.
rhardo:
It is still safer to use the method "POST", and you would not need any of this.
------------------
YAY! 200 POSTS! WOOT!
(only 150 more to go ;))