Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-15-2012, 04:45 PM   PM User | #1
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
Exclamation Line Break issues in TEXTAREA

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
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?
sanomani is offline   Reply With Quote
Old 11-15-2012, 05:43 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
sanomani (11-21-2012)
Old 11-21-2012, 04:39 AM   PM User | #3
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
Thanks for replying, Fou-Lu.

I get "\r\n" instead of line break.
Couldnt fix it in weeks.
sanomani is offline   Reply With Quote
Old 11-21-2012, 01:49 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
What is $posts? Where is it populated from?
Fou-Lu is offline   Reply With Quote
Old 11-25-2012, 07:00 PM   PM User | #5
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
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>
sanomani is offline   Reply With Quote
Old 11-25-2012, 07:10 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Still doesn't answer my question; what is $posts populated with?
Fou-Lu is offline   Reply With Quote
Old 11-30-2012, 05:32 PM   PM User | #7
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
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 is offline   Reply With Quote
Old 11-30-2012, 05:41 PM   PM User | #8
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
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.
sanomani is offline   Reply With Quote
Old 11-30-2012, 05:42 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by sanomani View Post
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.
Fou-Lu is offline   Reply With Quote
Old 11-30-2012, 07:40 PM   PM User | #10
Junsee
New Coder

 
Join Date: Jun 2012
Posts: 42
Thanks: 4
Thanked 5 Times in 5 Posts
Junsee is an unknown quantity at this point
I think he means
PHP Code:
$_POST['body'

and I always find this handy for stripping out magic quotes
PHP Code:
    if (get_magic_quotes_gpc()) {
        
$bodystripslashes($_POST['body']);
    } else {
        
$body $_POST['body'];
    } 
and this to get rid of nasti-ness
PHP Code:
    $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
PHP Code:
echo nl2br($body); 

Last edited by Junsee; 11-30-2012 at 07:45 PM.. Reason: answer question
Junsee is offline   Reply With Quote
Users who have thanked Junsee for this post:
sanomani (12-04-2012)
Old 12-04-2012, 06:39 PM   PM User | #11
sanomani
New Coder

 
Join Date: Jun 2012
Posts: 26
Thanks: 9
Thanked 0 Times in 0 Posts
sanomani is an unknown quantity at this point
Trying your tips Junsee.
I'll let everybody know what comes out.
sanomani is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:12 PM.


Advertisement
Log in to turn off these ads.