Page 1 of 1

Form Textareas...

Posted: Mon Feb 16, 2009 4:45 am
by lostprophetpunk
I am in the process of building a comment system for my website, however I have come across a problem.

I can get the comments displaying correctly when they are submitted to the database, but when I try to echo them out in the textarea they do not display properly. I will try and explain it below...

Say if the user typed in the textarea the following...

Hello, I do like this...

...My name is bob.

But if the user get's an error when submitting the form, it will not display like that when it is echoed out again, it will be something like this...

Hello, I do like this...\n\n\n\r\n\n\n\r...My Name is bob.

It would display all in one block. So how would I be able to echo it out again just as the user typed it in the first place?

I have already tried using nl2br() and also stripslashes().

Thanks in advance.

Re: Form Textareas...

Posted: Mon Feb 16, 2009 3:12 pm
by SpecialK
When you are displaying it after an error, is it being displayed inside the textarea again, or as HTML?

Re: Form Textareas...

Posted: Mon Feb 16, 2009 3:56 pm
by Bill H
Check the nl2br() function.

Re: Form Textareas...

Posted: Tue Feb 17, 2009 2:56 am
by lostprophetpunk
Bill H wrote:Check the nl2br() function.
If you were to read my original post you would see that I have already tried that function already...
SpecialK wrote:When you are displaying it after an error, is it being displayed inside the textarea again, or as HTML?
It is being echoed into the textarea.

Re: Form Textareas...

Posted: Tue Feb 17, 2009 3:09 am
by mattpointblank
Are you using any functions on the inputted text? Specifically, mysql_real_escape_string() or htmlentities()?

textarea poda koiyanga

Posted: Tue Feb 17, 2009 4:43 am
by nagarajan
<textarea width="50' height="89">

Re: textarea poda koiyanga

Posted: Tue Feb 17, 2009 5:27 am
by lostprophetpunk
nagarajan wrote:<textarea width="50' height="89">
What are you doing?
mattpointblank wrote:Are you using any functions on the inputted text? Specifically, mysql_real_escape_string() or htmlentities()?
Yes, I am using mysql_real_escape_string() on the inputted text.

Re: Form Textareas...

Posted: Tue Feb 17, 2009 6:32 am
by mattpointblank
There's your problem - it escapes the linebreaks so they won't display as linebreaks again in the textarea. Try using stripslashes() on it before outputting it. If you're allowing HTML into the textbox it's going to be even more complicated...