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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.