Thanks NogDog, I spent the last hour crying and laughing. I checked my HTML and it was like driving in a new city with the wrong map. I fixed that 😃
now after reading the FAQ I have even more questions...... ok not that many. The form works, the PHP you gave me was added but the form is still submitted regardless of whether there are errors or not and it does go to the error page (notfound.htm) when it should.
Can I ask for help with making sure every field filled ?
(can the code be modified to check all/any fields for "http" or "www"?
thanks
Here is my code.
<?php
$EmailFrom = "MYwebsite ";
$EmailTo = "something@gmail.com";
$Subject = "web site contact form";
$Name = Trim(stripslashes($_POST['Name']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=notfound.html\">";
exit;
}
if(preg_match('#\b(http?://|www.)#i', $Comments)) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=notfound.html\">";
exit;
}
else {
// it's okay
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailAddress;
$Body .= "\n";
$Body .= "Phone Number: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "City: ";
$Body .= $City;
$Body .= "\n";
$Body .= "Interested in: ";
$Body .= $Iaminterestedin;
$Body .= "\n";
$Body .= "Item number or description: ";
$Body .= $listofparts;
$Body .= "\n";
$Body .= "How you learned of TMMC: ";
$Body .= $Howdidyouhearaboutus;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ty.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=notfound.html\">";
}
?>