I have a html form and a php script processing the input of the form for validation purposes but im facing an issue. if the form is empty, it will not execute the first header in the if statement which is header("Location: error.html?mailerror");
instead it straight away execute the header in the elseif statement which is header("Location: thanks.html?mailsend");
. I wrote this php validation script to ensure that users do not submit an empty form but it seems like it wont work. Really appreciate if you could help me out.
I have tried putting an echo in the first if statement and it executes properly for example, when a user submit an empty form, it would echo 'Please fill up all fields' Now I'm trying to put a header that points to an error.html document. That is why i replaced the echo to header just like the one is the else if statement with the only difference that it points to the error.html page.
<?php
if(isset($_POST['submit'])){
$salutation=$_POST['salutation'];
$name=$_POST['name'];
$subject=$_POST['subject'];
$contact=$_POST['contact'];
$mailFrom=$_POST['mail'];
$date=$_POST['date'];
$event=$_POST['event'];
$address=$_POST['address'];
/* If form IS empty it will execute the code below */
if(empty($salutation)||empty($name)||empty($subject)||empty($contact)||empty($mail)||empty($date)||empty($event)||empty($address)){
header("Location: error.html?mailerror");
}
/* If the form is NOT empty it will execute the code below */
elseif(!empty($salutation)||empty($name)||empty($subject)||empty($contact)||empty($mail)||empty($date)||empty($event)||empty($address))
$mailTo="test@fairus-test-site.webstarterz.com";
$headers="From: ".$mailFrom;
$txt = "You have receive a booking from
".$salutation." ".$name."
Contact Number: ".$contact.".
Event Date: ".$date.".
Type of Event: ".$event.".
Package Selected : ".$subject.".
Event Address: ".$address;
mail($mailTo,$subject,$txt,$headers);
header("Location: thanks.html?mailsend");
}
Once user click submit, it will execute the second if else statement even when the form is empty