#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3

    Question Echo textarea - missing data!?


    Hi all,

    I've got a textarea (in a "review" page) that I'm trying to echo what the user inputed on the previous page, but lines of data are lost.

    From the input page:
    PHP Code:
    <textarea name="txtArea" cols="60" rows="7" id="maxcharfield" 
    onKeyDown="textAreaCounter(this,'add_txt_progressbar1',250)" 
    onKeyUp="textAreaCounter(this,'add_txt_progressbar1',250)" 
    onFocus="textAreaCounter(this,'add_txt_progressbar1',250)" ></textarea

    From the "review" page:
    PHP Code:
    // Prior to echo the textarea, I'm doing this to convert newlines to html <br>.

    $txtArea = nl2br($txtArea);  

    ...


    <textarea name="txtArea" cols="60" rows="7" id="maxcharfield" onKeyDown="textAreaCounter(this,'add_txt_progressbar1',250)" onKeyUp="textAreaCounter(this,'add_txt_progressbar1',250)" onFocus="textAreaCounter(this,'add_txt_progressbar1',250)"><? echo $txtArea?></textarea>
    If I echo out what's posted:
    PHP Code:
    reset ($HTTP_POST_VARS);
    while (list (
    $key$val) = each ($HTTP_POST_VARS)) {
        echo 
    "<font color='red'>$key</font>&nbsp;&nbsp;$val<br>";

    I can see that $txtArea does, in fact, have multiple lines of user input (when multiple lines are entered). Yet, on the preview page, most of the input is lost/cut off/truncated so that just the first line is there and a portion of any second line (but not subsequent lines).

    The Javascript there is simply to alert the user to the progress of getting to the max of 250 characters limit. It's working as expected.

    There are no spaces (that I can tell), in the review page textarea code. I know that can sometimes cause a problem, so it's all one line of code verified in textpad with no newlines or spaces.

    I know that I'm not converting the <br> back to newlines prior to echoing it out in the review textarea. At this point, I just want all the lines of data that was entered, to be echo'd back.

    Ideas on why I'd be missing data here?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,397
    Rep Power
    594
    Where did you get the idea to use the deprecated '$HTTP_POST_VARS', w3schools? You did not post your form tag but make sure it uses method=post. Then use $_POST for your values. Once you do that, if you are still having trouble come back and post all your relevant code (PHP goes in [ PHP ] tags and HTML goes in [ CODE ] tags).
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2011
    Posts
    105
    Rep Power
    51
    You can't echo HTML in the textarea, it will break up the textarea tags.

    Dont use nl2br, keep the newlines (\n).

    If you want to show HTML as plain text in the textarea, use htmlentities

    Since it seems you want to echo user input, you may be better off using strip_tags which will remove (malicious) html.
    Post to Facebook using a Nokia 3310
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    Thanks for the replies. w3schools. lol. No, it's code that's been in place in a test environment and commented out since 2004.

    Thinking a bit more about it, we don't "need" to convert the newlines to <br>, so the nl2br conversion has been removed.

    Now, when I enter (in the initial textarea):

    Line one.
    Line two.
    Line three.
    On the review page, this is echo'd out:

    Line one.
    Line two.
    Line three is missing. Ideas on what might be causing some data to be missing?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    Also...when I look at the review page source, I can see that the textarea does in fact have all the data entered. yet, not all of it is echo'd back in the textarea on the page.

    perhaps this is an issue with the Javascript?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2012
    Posts
    150
    Rep Power
    3
    argh...taking the js out of the textarea on the review page allows all of the data to be echo'd as expected.

    I'll take this up over on the javascript threads.

    thanks.

IMN logo majestic logo threadwatch logo seochat tools logo