Jump to content

slashes in web forms


turtleman8605

Recommended Posts

How do I get a web form to not add slashes when someone inputs a quote in a text field?

 

For example see www.morseavenuedesign.com/CinemaSightLines.com/sample_forum.php

 

That depends on how and why the slashes are being added.  It's difficult to diagnose the problem without the code.  I have seen this problem manifest when code escaped strings twice before submitting it to the database, resulting in some of the escape characters themselves being saved.

Link to comment
https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265362
Share on other sites

For database entry, I suggest using this function to escape the data instead of "addslashes" if that is what you are using.

<?php
function myEscape($string) {
       return  get_magic_quotes_gpc()?addcslashes(stripslashes ($string), "\x00\n\are\\'\"\x1a" ):addcslashes($string, "\x00\n\are\\'\"\x1a" );
}

foreach ($_REQUEST as $key => $val) {
      $_REQUEST[$key] = myEscape($val);
}
?>

 

If you just want to strictly display/email the data than I would do this:

 

<?php
foreach ($_REQUEST as $key => $val) {
         $_REQUEST[$key] = stripslashes($val);
}
?>

 

Note I used $_REQUEST because unsure if you are using get or post, feel free to substitute either or.

Link to comment
https://forums.phpfreaks.com/topic/53685-slashes-in-web-forms/#findComment-265633
Share on other sites

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.