In my form I have three groups of checkboxes. When someone selects no box in one group it gives back and echo error message:
[COLOR=“Red”][SIZE=“2”] Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public_html/mailer.php on line 15
Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public_html/mailer.php on line 18
Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public_html/mailer.php on line 21
Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public_html/mailer.php on line 24
Warning: Invalid argument supplied for foreach() in /home/jimmyweb/public_html/mailer.php on line 27[/COLOR][/SIZE]
here is my php:
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
how can I change it so it won’t give the message? do I change the {else}
echo or is there something I’m missing around my foreach?
my foreach
foreach($_POST['services'] as $value) {
$services_msg .="Services Desired: $value
";
}
Please help.
The $_POST data must contain an array to use a foreach on it
You need to check if it’s blank using isset($_POST[‘Services’]) before looping
Additionally - is this all the code? The stuff you posted?
You can’t use an else like that if so 
no, here is my full code. it is working except the messegaes =(
<?php
if(isset($_POST['submit'])) {
$to = "gabi@vertexmarketing.com";
$subject = "Talent/Materials Request Form";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$title_field = $_POST['title'];
$organization_field = $_POST['organization'];
$address_field = $_POST['address'];
$city_field = $_POST['city'];
$state_field = $_POST['state'];
$zip_field = $_POST['zip'];
$phone_field = $_POST['phone'];
$cell_field = $_POST['cell'];
foreach($_POST['services'] as $value) {
$services_msg .="Services Desired: $value
";
}
foreach($_POST['talent'] as $value) {
$talent_msg .="Talent Desired: $value
";
}
foreach($_POST['artists'] as $value) {
$artists_msg .="Artists Desired: $value
";
}
foreach($_POST['reels'] as $value) {
$reels_msg .="Reels Desired: $value
";
}
foreach($_POST['videos'] as $value) {
$videos_msg .="Videos Desired: $value
";
}
$date_field = $_POST['date'];
$time_field = $_POST['time'];
$ecity_field = $_POST['ecity'];
$estate_field = $_POST['estate'];
$country_field = $_POST['country'];
$people_field = $_POST['people'];
$budget_field = $_POST['budget'];
$message = $_POST['message'];
$body ="Name: $name_field
Title/Position: $title_field
Organization: $organization_field
Address: $address_field
City: $city_field
State: $state_field
Zip: $zip_field
Phone: $phone_field
Cell: $cell_field
E-Mail: $email_field
$services_msg
$talent_msg
$artists_msg
$reels_msg
$videos_msg
Event Date: $date_field
Time: $time_field
City: $ecity_field
State: $estate_field
Country: $country_field
# of People Attending: $people_field
Approximate Budget: $budget_field
Question/Comments:
$message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
} else {
echo "blarg!";
}
?>
If no checkboxes are checked, the $_POST[‘services’] array key will not be created. Just add a check to see if it exists first.
Yes. but I don’t want the error message if none of the boxes selected.
Put this at the beginning of your script:
error_reporting(0);
I prefer to turn off error reporting in my php.ini file. Google php.ini and you’ll find all kinds of stuff I’m sure…
It works !! =)
Thank you.
Turning off error reporting is just hiding a problem - the problem is that your code isn’t 100% right and you are just hiding the warning messages. Granted, the messages are just warnings and the code doesn’t cause any real problems but it’s the principal that counts - you don’t learn proper syntax or coding methods by dodging the errors