...

View Full Version : Line Break issues in TEXTAREA



sanomani
11-15-2012, 05:45 PM
Hi,
I've been searching for a solution for this problem. Browsed so many forums and sites but nothing solved the exact issue I am having.
So I've decided to write my case here.

I am using a textarea in my form, a simple form that will send an email using php.

Following is the code


<textarea name="body" rows="9">
<? if (isset($posts['body'])){echo $posts['body'];}?>
</textarea>


But when the form is submitted textarea input loses the line breaks and instead shows ugly /r/n


Any guidance?

Fou-Lu
11-15-2012, 06:43 PM
It literally shows the \r\n? Something has escaped it prematurely or it is being stored improperly in storage. If it shows /r/n, then something has been incorrectly replaced.
If it shows \r\n and $posts represents a direct copy of $_POST, you have magic_quotes_gpc enabled.

So to figure out the problem, can you specify where the $posts variable is populated from? Oh and clarify as well if its /r/n or \r\n.

sanomani
11-21-2012, 05:39 AM
Thanks for replying, Fou-Lu.

I get "\r\n" instead of line break.
Couldnt fix it in weeks.

Fou-Lu
11-21-2012, 02:49 PM
What is $posts? Where is it populated from?

sanomani
11-25-2012, 08:00 PM
Got the issue on contact page where we have a form.
in short its something like this..

<code>
<form method="post">
<textarea name="body" rows="9">
<? if (isset($posts['body'])){echo $posts['body'];}?>
</textarea>
<input type="submit" />
</form>
</code>

Fou-Lu
11-25-2012, 08:10 PM
Still doesn't answer my question; what is $posts populated with?

sanomani
11-30-2012, 06:32 PM
Hi,
I'm sorry i dont know much about coding terminology.
I am sending you a link to the website page in PM and also sending the codes there if thats okay.

Thanks in advance.

sanomani
11-30-2012, 06:41 PM
Well, you can check this form here.
http://shareyt.com/addsite.php?cl=y

First you need to complete a short signup process to see the page though.

Fou-Lu
11-30-2012, 06:42 PM
Hi,
I'm sorry i dont know much about coding terminology.
I am sending you a link to the website page in PM and also sending the codes there if thats okay.

Thanks in advance.

Don't bother, that would be pointless. You can't retrieve script source from rendered output.

Junsee
11-30-2012, 08:40 PM
I think he means


$_POST['body']



and I always find this handy for stripping out magic quotes


if (get_magic_quotes_gpc()) {
$body= stripslashes($_POST['body']);
} else {
$body = $_POST['body'];
}


and this to get rid of nasti-ness


$quotes = array('/"/',"/'/");
$replacements = array('&quot;','& # 39;');
$body = preg_replace($quotes,$replacements,$body);


Sorry and to answer the question
in the database ignore the /r/n but whe you want to echo use this


echo nl2br($body);

sanomani
12-04-2012, 07:39 PM
Trying your tips Junsee.
I'll let everybody know what comes out.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum