Jump to content

[SOLVED] Handling single quotes and double quotes on postback


webref.eu

Recommended Posts

Hi All

 

As a newbie, I would like to ask what the best way to handle form input with single quotes and double quotes when the form is posted back and has to be redisplayed. 

 

For example, currently, if a user populates my Username field with: 

 

test"test

 

(a double quote has been used in between two words).

 

and the form is posted back and has to be redisplayed (because of errors in other fields), then the Username field will get populated with: 

 

test\

 

... this being because I have magic quotes on and I am not handling the double quote properly so the string gets shortened. 

 

So what is the technique to allow: 

 

test"test

 

to be reposted back into the Username field.  Note, this should also work for the equivalent single quote situation. 

 

Thanks All.

you actually have 2 issues here. first, to get the slashes out that magic quotes adds, just wrap it in stripslashes(). But, you will still just get 'test' cus your input tag is being generated like so:

 

<input type="text" name="user" value="test"user" />

 

...obviously that double quote can't be in the middle there. to fix this, use htmlspecialchars():

 

<input type="text" name="user" value="<?php echo htmlspecialchars(stripslashes($_POST['user'])); ?>" />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.