Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • Users who have thanked Fou-Lu for this post:

    sanomani (11-21-2012)

  • #3
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Thanks for replying, Fou-Lu.

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

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    What is $posts? Where is it populated from?

  • #5
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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>

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Still doesn't answer my question; what is $posts populated with?

  • #7
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.

  • #8
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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.

  • #9
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.

  • #10
    Junsee
    Guest
    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

  • Users who have thanked Junsee for this post:

    sanomani (12-04-2012)

  • #11
    New Coder
    Join Date
    Jun 2012
    Posts
    26
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Trying your tips Junsee.
    I'll let everybody know what comes out.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •