I'm currently working on this order form: http://www.libertydelimart.com/order
Right now, all the items get posted to my email - regardless of weather information has been entered into the "How Many" text box.
What is the best way to exclude items that don't have anything entered in the "How Many" text box, so that only the items that do have information entered are emailed to me?
<?php
if(isset($_POST['submit'])) {
$to = "test@mywebsite.com";
$subject = "New Order";
$name_field = $_POST['name'];
$phone_field = $_POST['phone'];
$food = $_POST['food'];
$body = 'Name: ' . $name_field . PHP_EOL . 'Phone: ' . $phone_field . PHP_EOL;
//Check if any food items were set in order to prevent foreach error
if($food){
foreach ($food as $key => $item) {
$body .= $key . ' - ' . $item ['how_many'];
if($item['customize']) $body .= ' ('.$item['customize'].')' . PHP_EOL;
}
}
echo "Your Order Will Be Ready In 30 Minutes!";
mail($to, $subject, $body,"FROM: Deli <$to>");
print '<pre>'.$body.'</pre>';
}
?>