The validation code works perfectly in Opera (v.10.62), but I hit a problem in both Firefox (v.3.6.10) and IE (v.7). The code checks to see if any fields are empty (all are required), and checks if the e-mail address is a valid address.
Code: Select all
<?php
if (isset($_POST['email']))
{//if "email" is filled out, proceed
$email = $_POST['email'] ;
$name = $_POST['name'];
$message = $_POST['message'] ;
$emptyfields = FALSE;
// Are there any empty fields?
if (trim($email)=="" || trim($name)=="" || trim($message)=="")
{
$emptyfields = TRUE;
}
$validemail = validateaddress($email);
if ($emptyfields==TRUE)
{
echo "<p style=\"color:red\">An error occured:<br />- All the fields have to be filled in.</p>";
include("phpinclude/contact.php");
}
elseif ($validemail==FALSE)
{
echo "<p style=\"color:red\">An error occured:<br />- Invalid e-mail address.</p>";
include("phpinclude/contact.php");
}
else
{// Send e-mail
$subject = "Web e-mail";
mail_utf8("myaddress@somedomain.com", $subject,
$message, "From: $name <$email>" );
echo "Thank you.";
}
}
else
{// If the user has not yet submitted the form, display the form.
?>
<p>
Please send me an e-mail using the following form.
</p>
<?php
$email = "";
$name = "";
$message = "";
include("phpinclude/contact.php");
}
?>
Code: Select all
<form method='post' action='index.php?page=contact>
<table>
<tr><td>Name:</td><td><input type="text" name="name" size="40" value="<?php echo $name ?>" /></td></tr>
<tr><td>E-mail:</td><td><input type="text" name="email" size="40" value="<?php echo $email ?>" /></td></tr>
<tr><td>Message:</td><td><textarea rows="10" cols="60" name="message"><?php echo $message ?></textarea></td></tr>
<tr><td></td><td><input type="submit"></td></tr>
</table>
</form>
Any help is appreciated.