Forum Moderators: coopster

Message Too Old, No Replies

echo textarea in form validation

error in form validation page in text area

         

weddingm

2:11 pm on Jun 22, 2008 (gmt 0)

10+ Year Member



I have a form with textarea:

 <td><textarea name="Who_Now" rows="4" cols="50" MaxChars="750" id="text1" onkeypress="if (this.value.length >= parseInt(this.attributes['MaxChars'].value)) return false;" onkeyup=" document.getElementById( this.id+'_charsCount' ).innerHTML = (parseInt(this.attributes['MaxChars'].value)-parseInt(this.value.length))+' characters left.';"></textarea><br><span id="text1_charsCount">750 characters left</span></td>

Then I receive the info on the confrimation page:

$webinfo13=mysql_real_escape_string($_POST['Who_Now']);

Now if the form doesn't pass, I am trying to echo the info back into the textarea:

<textarea name="Who_Now" rows="4" cols="50"><?php echo stripslashes(htmlspecialchars($webinfo13); ?></textarea>

However the output is not what was typed if the user typed quotes into the textarea....? It works on the input fields but not in the textarea?

Any help?

venelin13

3:45 pm on Jun 22, 2008 (gmt 0)

10+ Year Member



Try this one:


<textarea name="Who_Now" rows="4" cols="50"><?php echo stripslashes($_POST['Who_Now']); ?></textarea>

weddingm

4:03 pm on Jun 22, 2008 (gmt 0)

10+ Year Member



The text area is blank.....maybe bacuase above I have the code:

$webinfo13=mysql_real_escape_string($_POST['Who_Now']);

I need it above in case the form does pass validation, then it gets submitted.

weddingm

5:03 pm on Jun 22, 2008 (gmt 0)

10+ Year Member



If I use

stripslashes(mysql_real_escape_string($webinfo13));

I still get

matt\'s \"test\"

cameraman

6:12 pm on Jun 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your whole problem may be in your first post. You're missing a parenthesis here:
<?php echo stripslashes(htmlspecialchars($webinfo13)); ?>

Consider this:
$a = "I say, \"How's it going\", what's up?";
$a = addslashes($a);
$a = addslashes($a);
$a = stripslashes($a);
echo $a;

will produce this:
I say, \"How\'s it going\", what\'s up?

Because you've added slashes twice and removed them once. stripslashes():

Returns a string with backslashes stripped off. (\' becomes ' and so on.) Double backslashes (\\) are made into a single backslash (\).

Although you're using mysql_real_escape_string to add the slashes, it has the same result:
$webinfo13=mysql_real_escape_string($_POST['Who_Now']);
stripslashes(mysql_real_escape_string($webinfo13));

weddingm

8:55 pm on Jun 23, 2008 (gmt 0)

10+ Year Member



thanks, now I got it to work