Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
echo in tectarea when validating form
Old 06-22-2008, 11:09 AM echo in tectarea when validating form
Skilled Talker

Posts: 69
Trades: 0
I have a form with textarea:

Code:
  <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:

Code:
$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:

Code:
<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?
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-22-2008, 11:19 AM Re: echo in tectarea when validating form
Extreme Talker

Posts: 177
Trades: 0
PHP Code:
$webinfo13=mysql_real_escape_string($_POST['Who_Now']); 
The escape should remove the quotes and double quotes from the input. So even if they're entering them...they don't get saved, at least....I'm pretty sure.

http://us3.php.net/mysql_real_escape_string

edit:

But one thing I can think of...Is I'm assuming you're echo'ing a session variable? What I would do is....

Code:
if(!formPasses)
{
session echo = $_POST['Who_Now']
}
else
{
session echo = mysql_real_escape_string($_POST['Who_Now']);
}
that way, when the form fails, they see what they inputted, otherwise, you save what you want to be inputted (the escaped string)

Last edited by kbfirebreather; 06-22-2008 at 11:21 AM..
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 06-22-2008, 11:25 AM Re: echo in tectarea when validating form
Skilled Talker

Posts: 69
Trades: 0
If I enter into the form textarea:

Matt's "test<br>Matt's "test<br>Matt's "test

the code I use to show what they typed in the validation page (before submitting to database:

Code:
<textarea name="Who_Now" rows="4" cols="50"><?php echo ($webinfo13); ?></textarea
and I get..

matt\'s \"test\"<br>\r\nmatt\'s \"test\"<br>\r\nmatt\'s \"test\"
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
Old 06-22-2008, 03:09 PM Re: echo in tectarea when validating form
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Quote:
Originally Posted by weddingm View Post
I have a form with textarea:

Code:
  <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:

Code:
$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:

Code:
<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?
I think your problem is this line:
<?php echo stripslashes(htmlspecialchars($webinfo13); ?>

You missed a bracket
<?php echo stripslashes(htmlspecialchars($webinfo13)); ?>
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 06-22-2008, 08:11 PM Re: echo in tectarea when validating form
Skilled Talker

Posts: 69
Trades: 0
Quote:
You missed a bracket
<?php echo stripslashes(htmlspecialchars($webinfo13)); ?>
now I get

matt's "test"<br>rnmatt's "test"<br>rnmatt's "test"<br>rnmatt's "test"<br>rnmatt's "test"
__________________
Matt
webmaster of
Please login or register to view this content. Registration is FREE
- Online wedding planning
weddingm is offline
Reply With Quote
View Public Profile
 
Old 06-23-2008, 12:18 PM Re: echo in tectarea when validating form
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Can you please specify what you want it to output in that example?
__________________

Please login or register to view this content. Registration is FREE
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 06-24-2008, 10:32 AM Re: echo in tectarea when validating form
Skilled Talker

Posts: 71
Trades: 0
Code:
<?php echo str_replace ("<br>","\n",stripslashes(htmlspecialchars($webinfo13))); ?>
Try this. Should convert <br> to the regular \n line break.
CrazeDizzleD is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to echo in tectarea when validating form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24953 seconds with 12 queries