simple bit of php - slashes being added

Joined
12 Feb 2006
Posts
17,643
Location
Surrey
i have a contact form which works fine except when the user adds an ' it adds slashes and looks messy on my end and then when replied to as the message is quoted in the email.

i tried stripslahes, htmlentities and urlencode but these cause problems when the user incorrectly fills out a field and then is shown the form again with the information that they filled out.

what would be the correct way to deal with the information that goes along this path.

user fills info and submits
method used is post
each bit of info is created into v****ble, e.g. $name = $_POST['name'];
check a few things to make sure email is a real address, contact number is number etc
if all is correct send email
if incorrect show form again and set value of input field to $name, $email etc
 
Can't you just call stripslashes during the email call and leave the slashes in for redisplaying the form?

PHP:
$result = mail("[email protected]", "Test", stripslashes($message));
 
just calling stripslahes and nothing else doesn't work as the ' is making the input field end too early, e.g. <input type='text' value='it's a wonderful day'/>

all i see if the word it

same problem if i change to "
 
Sounds like magic_quotes_gpc is set on your server and is therefore escaping any ' or ". Either disable it if you have control, or stripslashes() should work.
Show some more code if it's still not working.
 
Using htmlspecialchars("mystring", ENT_QUOTES) solved the problem for me once. I had to do this to the data once it was pulled from the database to a page and then submitted it via form(POST) to another.
 
Back
Top Bottom