Form Textareas...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lostprophetpunk
Forum Newbie
Posts: 21
Joined: Sat May 31, 2008 3:49 am

Form Textareas...

Post 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.
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: Form Textareas...

Post by SpecialK »

When you are displaying it after an error, is it being displayed inside the textarea again, or as HTML?
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Form Textareas...

Post by Bill H »

Check the nl2br() function.
lostprophetpunk
Forum Newbie
Posts: 21
Joined: Sat May 31, 2008 3:49 am

Re: Form Textareas...

Post 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.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Form Textareas...

Post by mattpointblank »

Are you using any functions on the inputted text? Specifically, mysql_real_escape_string() or htmlentities()?
nagarajan
Forum Newbie
Posts: 2
Joined: Tue Feb 17, 2009 4:38 am

textarea poda koiyanga

Post by nagarajan »

<textarea width="50' height="89">
lostprophetpunk
Forum Newbie
Posts: 21
Joined: Sat May 31, 2008 3:49 am

Re: textarea poda koiyanga

Post 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.
mattpointblank
Forum Contributor
Posts: 304
Joined: Tue Dec 23, 2008 6:29 am

Re: Form Textareas...

Post 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...
Post Reply