Form shows '/' in every field
My php script to send mail is as follows :
<?php
if (isset($_POST['submit'])) {
$to='info@animalswecare.com';
$fname=stripslashes($_POST['fname']);
$email=$_POST['email'];
if (get_magic_quotes_gpc())
$email = stripslashes($email);
//$email=trim($email, '/');
$msg=$_POST['msg'];
$msg=stripslashes($msg);
$message="Name: $fname\n" ."Message: $msg\n";
mail($to,$subject,$message,'From:'.$email) ;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="contact us">
<label>Name:</label>
<input type="text" name="fname" value=<?php if(!empty($fname)) echo $fname; ?> /><br />
<label>Email:</label>
<input type="text" name="email" value=<?php if (!empty($email)) echo $email; ?> /><br />
<label>Message:</label>
<textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea> <br />
<input type="submit" name="submit" value="Post" />
</form>
But when the form appears, there is a /
added in every field.
开发者_开发技巧I have tried using trim
, rtim
, get magic quotes and stripslashes
but nothing is working.
It because your value=
's are not being ended.
Try this: <input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>" />
and apply the same learning's to all of the inputs.
Also I re-formatted your code and added label
in the CSS..so you don't have use those ugly line-spaces.
<?php
if (isset($_POST['submit'])) {
$to = 'info@animalswecare.com';
$fname = stripslashes($_POST['fname']);
$email = $_POST['email'];
if (get_magic_quotes_gpc()) {
$email = stripslashes($email);
}
// $email = trim($email, '/');
$msg = $_POST['msg'];
$msg = stripslashes($msg);
$message = "Name: $fname\n" ."Message: $msg\n";
mail($to, $subject, $message, 'From:' . $email);
}
?>
<style>
label {width: 120px;}
</style>
<form action="" method="post">
<label>Name:</label>
<input type="text" name="fname" value="<?php if(!empty($fname)) echo $fname; ?>" /><br />
<label>Email:</label>
<input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" /><br />
<label>Message:</label>
<textarea name="msg" rows="5"><?php if (!empty($msg)) echo $msg; ?></textarea><br />
<input type="submit" name="submit" value="Post" />
</form>
try adding " " around the value attribute
ie
<input type="text" name="email" value="<?php if (!empty($email)) echo $email; ?>" />
This will teach you to follow standards and always enclose tag parameter values in quotes
First of all, don't use stripslashes(). Simply disable magic_quotes_gpc completely, using the php.ini file or .htaccess. If you can't, view the accepted answer to this question: How to turn off magic quotes on shared hosting?
About your error...
value=<?php if (!empty($email)) echo $email; ?> />
If you look, you didn't put the quotes around the attribute "value".
value="<?php if (!empty($email)) echo $email; ?>" />
will fix it
精彩评论