Jump to content

remove quotes from submited in forms


dezkit

Recommended Posts

Huh?  What do you mean?  You have 270+ posts, so I'll assume that you know how to handle form data...You want the receiving script to remove the quotes, correct?  Or do you just want them to not be allowed in the text box?  That'll be Javascript.

as stated above you could use the str_replace() Function

or if you want to allow only certain characters to come through in the fields you can try the following

 

$strip_message = $_POST['something'];

$message = ereg_replace("[^A-Za-z0-9]", "", $strip_message );

 

This will only allow the characters A-Z a-z and the numbers 0-9 to come through on your fields, give it a try, if you need you can add more things to allow to not be stripped just add them in

dude, you don't want any quotes in the posted data. We've already posted the code to strip any quotes from the strings that your user posts.

 

I'll try to break it down one more time.

 

your html form has an input with name='something' like your example above

 

once that form is submitted, you need to get the post with the name something

 

$something = $_POST['something'];

 

now you want to strip single quotes from the string

$something = str_replace("'", '', $something);

 

now you still need to strip double quotes

$something = str_replace('"', '', $something);

 

does that help man?

<?php

$strip_something = $_POST['something'];

$something = ereg_replace("[^A-Za-z0-9]", "", $something );

?>

<form action="<? $_SERVER['PHP_SELF']; ?>">

<table>

<tr>

<td>Something:

<td><input type="text" name="something" value="<?php echo $something; ?>" >

</table>

<input name="submit" type="submit" value="Submit" />

<input id="button2" type="reset" value="Reset" /></form>

Or as stated twice now by mlin  8) You can simply use the str_replace function and strip the varialbe $something.  You must have the value set to value="<?php echo $something; ?>"    Good Luck!!!!!!!

 

 

<?php

$something = str_replace("'", '', $something);

$something = str_replace('"', '', $something);

?>

<form action="<? $_SERVER['PHP_SELF']; ?>">

<table>

<tr>

<td>Something:

<td><input type="text" name="something" value="<?php echo $something; ?>" >

</table>

<input name="submit" type="submit" value="Submit" />

<input id="button2" type="reset" value="Reset" /></form>

 

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.