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
Code:<?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\n" . 'Reply-To: '.$email."\r\n" . 'X-Mailer: PHP/' . phpversion(); $subject = 'Car instruction form From wedding Cars Manchester'; $body='Car instruction form From wedding Cars Manchester'."\n\n"; $body.='Wedding Date: '.$date."\n\n"; $body.='Time Of Service: '.$time."\n\n"; $body.='Brides Name: '.$bname."\n\n"; $body.='Brides Phone: '.$bphone."\n\n"; $body.='Grooms Name: '.$gname."\n\n"; $body.='Grooms Phone: '.$gphone."\n\n"; $body.='Church Name: '.$cname."\n\n"; $body.='Church Address: '."\n".$cadd."\n\n"; $body.='Church Postcode: '.$cpost."\n\n"; $body.='Reception Name: '.$recname."\n\n"; $body.='Reception Address: '."\n".$recadd."\n\n"; $body.='Reception Postcode: '.$recpost."\n\n"; $body.='Senders Name: '.$name."\n\n"; $body.='Email Address: '.$email."\n\n"; $body.='Special Instructions: '."\n".$inst."\n\n"; $body.='Car 1: '.$car1."\n\n"; $body.='Time at house for: '.$c1tim."\n\n\n"; $body.='Pick Up Number: '.$c1pic."\n\n"; $body.='Trips From House: '.$c1tri."\n\n"; $body.='Guests To Be Taken To Church: '."\n".$c1gu."\n\n"; $body.='Address To Be Picked Up From: '."\n".$c1ad."\n\n"; $body.='Postcode: '.$c1pos."\n\n"; $body.='Car 2: '.$car2."\n\n"; $body.='Time at house for: '.$c2tim."\n\n"; $body.='Pick Up Number: '.$c2pic."\n\n"; $body.='Trips From House: '.$c2tri."\n\n"; $body.='Guests To Be Taken To Church: '."\n".$c2gu."\n\n"; $body.='Address To Be Picked Up From: '."\n".$c2ad."\n\n"; $body.='Postcode: '.$c2pos."\n\n"; $body.='Car 3: '.$car3."\n\n"; $body.='Time at house for: '.$c3tim."\n\n"; $body.='Pick Up Number: '.$c3pic."\n\n"; $body.='Trips From House: '.$c3tri."\n\n"; $body.='Guests To Be Taken To Church: '."\n".$c3gu."\n\n"; $body.='Address To Be Picked Up From: '."\n".$c3ad."\n\n"; $body.='Postcode: '.$c3pos."\n\n"; if(mail($to, $subject, $body, $headers)) { die('Thanks. We will be back to you soon.'); } else { die('Error: Mail failed'); } ?>



Reply With Quote


Bookmarks