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
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: 186
Location: London UK
Trades: 0
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
 
 
Register now for full access!
Old 10-26-2007, 04:52 PM Re: single and double quotes in form validating
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
You can always escape your quotes.

PHP Code:
<?
echo '\''
?>
This will output '
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-26-2007, 07:20 PM Re: single and double quotes in form validating
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
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 Visit lizciz's homepage!
 
Old 10-26-2007, 08:00 PM Re: single and double quotes in form validating
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
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: 410
Name: Harry Burt
Location: Colchester, Essex, England
Trades: 0
Mary's chicken's what? What is it that Mary's chicken has? Just kidding of course...
__________________
Foundation Flash tutorials :
Please login or register to view this content. Registration is FREE


New Dreamed Up Web Design:
Please login or register to view this content. Registration is FREE
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
Trades: 0
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
Defies a Status

Posts: 1,606
Trades: 0
Quote:
echo stripslashes($str);
or whatever you are using to print it to the screen.
__________________
Colbyt

Please login or register to view this content. Registration is FREE
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: 186
Location: London UK
Trades: 0
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
Trades: 0
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
Trades: 0
.. 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 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.33651 seconds with 12 queries