Making Form Field Mandatory
Posted: Thu Jan 06, 2011 6:10 pm
I've been trying to make my contact form engine mandatory for the name, phone number and email fields, but when I upload it on the ftp and test it, I keep getting errors. Here's the code I have that is working without the fields being mandatory:
I would like it to return something that says: "Enter Your Name/Phone Number/Email" corresponding to the appropriate field they didn't fill out. Thanks for any input you can provide!
Code: Select all
<?php
$EmailFrom = "example@gmail.com";
$EmailTo = "example@gmail.com";
$EmailTo = "example@gmail.com";
$EmailTo = "example@gmail.com";
$Subject = "New Lead!!!";
$Name = Trim(stripslashes($_POST['Name']));
$Phone_Number = Trim(stripslashes($_POST['Phone_Number']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Phone Number: ";
$Body .= $Phone_Number;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success) {//&& ($Phone_Number != "" || $Email != "") {
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>