Forum Moderators: coopster

Message Too Old, No Replies

apostrophe causing disappearing text

         

mrnoisy

11:39 am on Jul 3, 2005 (gmt 0)

10+ Year Member



I have a simple form that actions to itself with php_self and displays the submitted data in the input boxes.

Whenever the data contains an apostrophe, whatever is after the apostrophe disappears.

I've played around with addslashes() and stripslashes() but no luck.

input: Bob O'reilly


if(isset($_POST['form1']))
{
$lastname=($_POST['lastname']);
}

print "<form action='$php_self'>";
print "<input type='text' name='lastname' value='$lastname' />";
print "<input type='submit' name='form1' />";
print "</form>";

output: Bob O\


if(isset($_POST['form1']))
{
$lastname=($_POST['lastname']);
}

print "<form action='$php_self'>";
print "<input type='text' name='lastname' value='".stripslashes($lastname)."' />";
print "<input type='submit' name='form1' />";
print "</form>";

output: Bob O

j4mes

11:49 am on Jul 3, 2005 (gmt 0)

10+ Year Member



htmlspecialchars()

mrnoisy

12:18 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



Thanks for the heads up j4mes.

I'm not sure why, but I still have to stripslashes() on display to make it work.

input: Bob O'reilly


if(isset($_POST['form1']))
{
$lastname=htmlentities($_POST['lastname'], ENT_QUOTES);
}

print "<form action='$php_self'>";
print "<input type='text' name='lastname' value='".stripslashes($lastname)."' />";
print "<input type='submit' name='form1' />";
print "</form>";

output: Bob O'reilly

Now I'm trying to validate the input to characters found in a name besides letters, such as ' and - but the apostrophe is not validating.

((eregi('^[a-zA-Z \'-]{1,50}$', $lastname))

mrnoisy

12:35 pm on Jul 3, 2005 (gmt 0)

10+ Year Member



OK I got it:


(ereg("^[\w]+([- ]{1}¦(\\\'))?[\w]+$", $lastname))