Reply
single and double quotes in form validating
Old 10-26-2007, 04:09 PM single and double quotes in form validating
hiptobesquare's Avatar
Extreme Talker

Posts: 162
Location: London UK
Hi

I have a form in which i want the user to be able to enter single quotes (mary's chicken's), this is no problem and the form submits as it should.

However, if, on my handing page an error is discovered and i need to redirect the user to the form again, how would i enable the full string of the entered data (mary's chicken's said) to automatically load up in the input box.

PHP Code:
$_SESSION[mary]="mary's chicken's";

<input type='text' value='<?PHP echo $_SESSION[mary];?>' name='mary'>
will output
HTML Code:
<input type='text' value='mary' name='mary'>
I could obviously in this case use double quotes to surround the relevant variables, but then im stuck with the same issue if my user decides to use double quotes.

Is this just a flaw in programming which i have to live with ? Id really like to figure out a way around it.

Thanks in advance, mark
hiptobesquare is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-26-2007, 04:52 PM Re: single and double quotes in form validating
NullPointer's Avatar
Will Code for Food

Posts: 502
Name: Matt
Location: Irvine, CA
You can always escape your quotes.

PHP Code:
<?
echo '\''
?>
This will output '
__________________
http://tinsology.com/ - Under construction
NullPointer is online now
Reply With Quote
View Public Profile
 
Old 10-26-2007, 07:20 PM Re: single and double quotes in form validating
Skilled Talker

Posts: 73
Name: Mattias Nordahl
Location: Sweden
Couldn't you just use double quotes in your input tags, as you mentioned? This would mean that all single quotes were displayed correctly and you could easily replace all double quotes with &quot;. I think that would work.
(Or simply escape all quotes, as NullPointer wrote.)
lizciz is offline
Reply With Quote
View Public Profile
 
Old 10-26-2007, 08:00 PM Re: single and double quotes in form validating
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Wireless Audio
Posts: 2,322
Name: Keith Marshall
Location: West Hartford, CT
Quote:
Originally Posted by lizciz View Post
Couldn't you just use double quotes in your input tags, as you mentioned? This would mean that all single quotes were displayed correctly and you could easily replace all double quotes with &quot;. I think that would work.
(Or simply escape all quotes, as NullPointer wrote.)

As said above, this is the typical way that most php web scripts are written. All html form tags use double quotes for the attribute values, and the var output is converted into html entities like this:

<input type="text" value="<? echo htmlentities($_SESSION['mary']); ?>" name="mary" />
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-28-2007, 06:01 AM Re: single and double quotes in form validating
Foundationflash's Avatar
Ultra Talker

Posts: 411
Name: Harry Burt
Location: Colchester, Essex, England
Mary's chicken's what? What is it that Mary's chicken has? Just kidding of course...
__________________
Foundation Flash tutorials : www.foundation-flash.com

New Dreamed Up Web Design: www.dreamedupdesign.com
Foundationflash is offline
Reply With Quote
View Public Profile Visit Foundationflash's homepage!
 
Old 10-28-2007, 08:11 AM Re: single and double quotes in form validating
Novice Talker

Posts: 10
Hello!

I also have problems with quotes.

I have a html page with textarea in a submit form. When I type into the textarea this line for example:
test: "name"

... and then post it to a php script, I get there this line:
test: \"name\"

It's happening even if I echo the data through the htmlspecialchar($data, ENT_QUOTES) function call.

How get rid of this?

Thanks!
funky86 is offline
Reply With Quote
View Public Profile
 
Old 10-28-2007, 08:17 AM Re: single and double quotes in form validating
King Spam Talker

Posts: 1,084
Quote:
echo stripslashes($str);
or whatever you are using to print it to the screen.
colbyt is offline
Reply With Quote
View Public Profile
 
Old 11-02-2007, 06:10 AM Re: single and double quotes in form validating
hiptobesquare's Avatar
Extreme Talker

Posts: 162
Location: London UK
thanks nullpointer, but that will only only escape quotes for entering mysql into th db, and not, as i require escape them in html output. lizciz and mcgraphic, thats exactly what i was looking for- htmlentities.

Thanks eveyone
hiptobesquare is offline
Reply With Quote
View Public Profile
 
Old 11-02-2007, 06:18 AM Re: single and double quotes in form validating
Novice Talker

Posts: 10
Oh and colbyt, thanks for your help. This solved my solution .
funky86 is offline
Reply With Quote
View Public Profile
 
Old 11-02-2007, 06:22 AM Re: single and double quotes in form validating
Novice Talker

Posts: 10
.. I mean problem ;D.
funky86 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to single and double quotes in form validating
 

Thread Tools

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

vB 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.16571 seconds with 12 queries