Tough love huh??
Right, I got rid of that messy table lay out and this appears to work okay, although i'd be extremely grateful if you'd give me your thoughts again? I'll then replicate this for my other 'contact form' fields (Name and Message) although slightly different validation will take place. Thanks a lot for your help, Ryan
CODE
<?php // shortform.php
$fail = $email = "";
$to = '
[email protected]';
$subject = 'Contact form email';
$message = 'please work!';
if (isset($_POST['email']))
$email = fix_string($_POST['email']);
$fail = validate_email($email);
echo "<html><head><title>Shortform</title>";
if ($fail =="") {
echo "</head><body>$email successfully validated: .</body></html>";
mail($to, $subject, $message, "From: $email");
exit;
}
if ((isset($_POST["Submitted"])) && ($fail !=""))
{
echo <<<_END
Sorry, the follwoing errors were found<br />
in your form - $fail<br />
_END;
}
echo <<<_END
<form method="post" action="shortform2.php"
onSubmit="return validate(this)">
Email: <input name='email' type="text" value=$email><br />
<input type="submit" value="Submit" />
<input type="hidden" name="Submitted" value="Yes"/>
</form>
_END;
function validate_email($email) {
if ($email == "") return "No Email was entered<br />";
else if (!((strpos($email, ".") > 0) &&
(strpos($email, "@") > 0)) ||
preg_match("/[^a-zA-Z0-9.@_-]/", $email))
return "The Email address is invalid<br />";
return "";
}
function fix_string($string) {
if (get_magic_quotes_gpc()) $string = stripslashes($string);
return htmlentities ($string);
}
?>