Results 1 to 3 of 3

Thread: POST info into variable removes carrage returns..

  1. #1

    Thread Starter
    Lively Member Daschle's Avatar
    Join Date
    Oct 2002
    Location
    Sunnyvale, CA
    Posts
    114

    POST info into variable removes carrage returns..

    I'm playing with an email script thingy. A user has a TEXTAREA and can key in a email to submit.

    Example at: http://www.ibarn.net/email

    If you key in a message with returns in it, and then submit, the returns are lost.

    Index HTML
    PHP Code:
    <form name="textmsg" method="post" action="http://www.ibarn.net/email/send.php">
    <
    textarea name="message" wrap=virtual cols=38 rows=10></textarea>
    </
    form
    Send PHP
    PHP Code:
    $message $_POST['message'];
    echo(
    "$message"); 
    Somewhere in these lines the formatting is getting removed. I assume it's something stupid, me not using an argument, or the wrong command (echo instead of something else.. though I've tried PRINT already.)

    This is probably really basic, and a real "DUH" cantidate.. but any help would be greatly appreciated.

    I'm writing this for the experience, not because I need the program. If I needed it, I could simply go download any of a thousand other existing ones. I seek learning, not utility..

    Thank you.
    "It's difficult to imagine a world in which people voluntarily choose to listen to liberals. There is no evidence that it has ever happened. " - Ann Coulter

  2. #2

    Thread Starter
    Lively Member Daschle's Avatar
    Join Date
    Oct 2002
    Location
    Sunnyvale, CA
    Posts
    114
    Just to clarify,

    The actual email send DOES have the returns in it. It is merely the ECHO or PRINT that's losing the returns. The $message variable *does* include the returns, as shown by the email submission.

    And FWIW, the email thing is sending now, so if you're bored and trying it out, don't put anything overly silly and stuff.
    "It's difficult to imagine a world in which people voluntarily choose to listen to liberals. There is no evidence that it has ever happened. " - Ann Coulter

  3. #3
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Newlines will not show up in a webpage. You need to replace them with <br /> using the function nl2br():

    Code:
    $message = $_POST['message']; //wah? This is redundant
    echo(nl2br($message));
    
    //even better:
    echo nl2br($_POST['message']);
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width