form problem
Posted: Wed Sep 16, 2009 3:49 pm
ok, if i have something entered in the name input and the rest are blank it works fine and validates and wont send the form, but as soon as i enter something into the email input it tells me what i havent filled out but still sends the form even though the other areas are still blank. It only does this for the email input everything else works fine, the email part of the code starts on line 17.
Code: Select all
<?php
$errormsg = ""; //Initialize errors
//If form was submitted
if ($_POST['submitted']==1) {
//Do something
if ($_POST[name]){
$name = $_POST[name]; //If name was entered
}
else{
$errormsg = "Please enter your Name";
}
if ($_POST[email]){
$email = $_POST[email]; //If phone was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & Email";
}else{
$errormsg = "Please enter your Email";
}
}
if ($_POST[phone]){
$phone = $_POST[phone]; //If phone was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & Phone Number";
}else{
$errormsg = "Please enter your phone number";
}
}
if ($_POST[details]){
$details = $_POST[details]; //If phone was entered
}
else{
if ($errormsg){ //If there is already an error, add next error
$errormsg = $errormsg . " & A brief project description";
}else{
$errormsg = "Please enter a brief project description";
}
}
}
if ($errormsg){ //If any errors display them
echo "$errormsg";
}
if ($_POST["email"]<>'') {
$ToEmail .= 'me@brendanperkins.com';
$EmailSubject .= 'Quote Form';
$mailheader .= "From: ".$_POST["name"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY .= "Name/Company: ".$_POST["name"]."<br />";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br />";
$MESSAGE_BODY .= "Phone: ".$_POST["phone"]."<br />";
$MESSAGE_BODY .= "Time: ".$_POST["call_option"]."<br />";
$MESSAGE_BODY .= "Development for: ".$_POST["development_for"]."<br /><br />";
$MESSAGE_BODY .= "Project Details:<br /><br /> ".nl2br($_POST["details"])."<br />";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
if ($name != '' || $email != '' || $phone != '' || $details != '' )
?>
<div id="formmessage">
<p>Thank you for your submission. We are now thinking of the best possible solution for your project and will be back to you in the next 1 to 2 working days. If this is urgent contact info@designpilotonline.com or call us at 1 416 538 3003.
-Design Pilot</p>
<?php
} else {
?>