webref.eu Posted July 31, 2008 Share Posted July 31, 2008 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. Link to comment https://forums.phpfreaks.com/topic/117550-solved-handling-single-quotes-and-double-quotes-on-postback/ Share on other sites More sharing options...
rhodesa Posted July 31, 2008 Share Posted July 31, 2008 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'])); ?>" /> Link to comment https://forums.phpfreaks.com/topic/117550-solved-handling-single-quotes-and-double-quotes-on-postback/#findComment-604586 Share on other sites More sharing options...
webref.eu Posted July 31, 2008 Author Share Posted July 31, 2008 That's great ... thanks for that. Rgds Link to comment https://forums.phpfreaks.com/topic/117550-solved-handling-single-quotes-and-double-quotes-on-postback/#findComment-604686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.