I have a php contact form - very basic I must add but is there a way to not send form fields that are left blank. The form has required fields which must be completed and sent but its for a car hire company so only one car may be required so the details for the other two on the form would not be needed. I have added the code that I am using below
<?php
$date=$_POST['date'];
$time=$_POST['time'];
$bname=$_POST['bname'];
$bphone=$_POST['bphone'];
$gname=$_POST['gname'];
$gphone=$_POST['gphone'];
$cname=$_POST['cname'];
$cadd=$_POST['cadd'];
$cpost=$_POST['cpost'];
$recname=$_POST['recname'];
$recadd=$_POST['recadd'];
$name=$_POST['name'];
$recpost=$_POST['recpost'];
$email=$_POST['email'];
$inst=$_POST['inst'];
$car1=$_POST['car1'];
$c1tim=$_POST['c1tim'];
$c1pic=$_POST['c1pic'];
$c1tri=$_POST['c1tri'];
$c1gu=$_POST['c1gu'];
$c1ad=$_POST['c1ad'];
$c1pos=$_POST['c1pos'];
$car2=$_POST['car2'];
$c2tim=$_POST['c2tim'];
$c2pic=$_POST['c2pic'];
$c2tri=$_POST['c2tri'];
$c2gu=$_POST['c2gu'];
$c2ad=$_POST['c2ad'];
$c2pos=$_POST['c2pos'];
$car3=$_POST['car3'];
$c3tim=$_POST['c3tim'];
$c3pic=$_POST['c3pic'];
$c3tri=$_POST['c3tri'];
$c3gu=$_POST['c3gu'];
$c3ad=$_POST['c3ad'];
$c3pos=$_POST['c3pos'];
$to='admin@mysite.com';
$headers = 'From: '.$name."\\r\
" .
'Reply-To: '.$email."\\r\
" .
'X-Mailer: PHP/' . phpversion();
$subject = 'Car instruction form From wedding Cars Manchester';
$body='Car instruction form From wedding Cars Manchester'."\
\
";
$body.='Wedding Date: '.$date."\
\
";
$body.='Time Of Service: '.$time."\
\
";
$body.='Brides Name: '.$bname."\
\
";
$body.='Brides Phone: '.$bphone."\
\
";
$body.='Grooms Name: '.$gname."\
\
";
$body.='Grooms Phone: '.$gphone."\
\
";
$body.='Church Name: '.$cname."\
\
";
$body.='Church Address: '."\
".$cadd."\
\
";
$body.='Church Postcode: '.$cpost."\
\
";
$body.='Reception Name: '.$recname."\
\
";
$body.='Reception Address: '."\
".$recadd."\
\
";
$body.='Reception Postcode: '.$recpost."\
\
";
$body.='Senders Name: '.$name."\
\
";
$body.='Email Address: '.$email."\
\
";
$body.='Special Instructions: '."\
".$inst."\
\
";
$body.='Car 1: '.$car1."\
\
";
$body.='Time at house for: '.$c1tim."\
\
\
";
$body.='Pick Up Number: '.$c1pic."\
\
";
$body.='Trips From House: '.$c1tri."\
\
";
$body.='Guests To Be Taken To Church: '."\
".$c1gu."\
\
";
$body.='Address To Be Picked Up From: '."\
".$c1ad."\
\
";
$body.='Postcode: '.$c1pos."\
\
";
$body.='Car 2: '.$car2."\
\
";
$body.='Time at house for: '.$c2tim."\
\
";
$body.='Pick Up Number: '.$c2pic."\
\
";
$body.='Trips From House: '.$c2tri."\
\
";
$body.='Guests To Be Taken To Church: '."\
".$c2gu."\
\
";
$body.='Address To Be Picked Up From: '."\
".$c2ad."\
\
";
$body.='Postcode: '.$c2pos."\
\
";
$body.='Car 3: '.$car3."\
\
";
$body.='Time at house for: '.$c3tim."\
\
";
$body.='Pick Up Number: '.$c3pic."\
\
";
$body.='Trips From House: '.$c3tri."\
\
";
$body.='Guests To Be Taken To Church: '."\
".$c3gu."\
\
";
$body.='Address To Be Picked Up From: '."\
".$c3ad."\
\
";
$body.='Postcode: '.$c3pos."\
\
";
if(mail($to, $subject, $body, $headers)) {
die('Thanks. We will be back to you soon.');
} else {
die('Error: Mail failed');
}
?>