# PHP email form not returning multiple checkboxes



## MDLarson (May 31, 2005)

I have a monster HTML form located here:
http://www.stonemountainpetlodge.com/contact/registration_dog/email.html

The checkboxes in question are located a bit down on the page, and start with Daily Brush, Frosty Paws Treat, Morning Walk, etc.  Each checkbox is coded in this manner:

```
<input name="dog_1_services_basic_regular[]" type="checkbox" id="dog_1_services_basic_regular[]" value="Daily Brush">
```
When the form is submitted, it runs a PHP script (emailer.php) that looks like this:

```
<?php

// Variables from form input
$customer_id_number = $_POST['customer_id_number'];
$dropoff_date = $_POST['dropoff_date'];
$pickup_date = $_POST['pickup_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$daytime_phone = $_POST['daytime_phone'];
$evening_phone = $_POST['evening_phone'];
$mobile_phone = $_POST['mobile_phone'];
$doctor_name = $_POST['doctor_name'];
$clinic_name = $_POST['clinic_name'];
$clinic_phone = $_POST['clinic_phone'];
$dog_bitten = $_POST['dog_bitten'];
$lodging_plan = $_POST['lodging_plan'];
$dog_1_name = $_POST['dog_1_name'];
$dog_1_breed = $_POST['dog_1_breed'];
$dog_1_sex = $_POST['dog_1_sex'];
$dog_1_sterilized = $_POST['dog_1_sterilized'];
$dog_1_birthdate = $_POST['dog_1_birthdate'];
$dog_1_rabies_immunization_date = $_POST['dog_1_rabies_immunization_date'];
$dog_1_bordetella_immunization_date = $_POST['dog_1_bordetella_immunization_date'];
$dog_1_dhlpp_immunization_date = $_POST['dog_1_dhlpp_immunization_date'];
$dog_1_services_basic_regular = $_POST['dog_1_services_basic_regular'];
$dog_1_services_basic_peak = $_POST['dog_1_services_basic_peak'];
$dog_1_services_delights_regular = $_POST['dog_1_services_delights_regular'];
$dog_1_services_delights_peak = $_POST['dog_1_services_delights_peak'];
$dog_1_walk_or_exercise = $_POST['dog_1_walk_or_exercise'];
$dog_1_services_doggy_day_lodge = $_POST['dog_1_services_doggy_day_lodge'];
$dog_2_name = $_POST['dog_2_name'];
$dog_2_breed = $_POST['dog_2_breed'];
$dog_2_sex = $_POST['dog_2_sex'];
$dog_2_sterilized = $_POST['dog_2_sterilized'];
$dog_2_birthdate = $_POST['dog_2_birthdate'];
$dog_2_rabies_immunization_date = $_POST['dog_2_rabies_immunization_date'];
$dog_2_bordetella_immunization_date = $_POST['dog_2_bordetella_immunization_date'];
$dog_2_dhlpp_immunization_date = $_POST['dog_2_dhlpp_immunization_date'];
$dog_2_services_basic_regular = $_POST['dog_2_services_basic_regular'];
$dog_2_services_basic_peak = $_POST['dog_2_services_basic_peak'];
$dog_2_services_delights_regular = $_POST['dog_2_services_delights_regular'];
$dog_2_services_delights_peak = $_POST['dog_2_services_delights_peak'];
$dog_2_walk_or_exercise = $_POST['dog_2_walk_or_exercise'];
$dog_2_services_doggy_day_lodge = $_POST['dog_2_services_doggy_day_lodge'];
$dog_3_name = $_POST['dog_3_name'];
$dog_3_breed = $_POST['dog_3_breed'];
$dog_3_sex = $_POST['dog_3_sex'];
$dog_3_sterilized = $_POST['dog_3_sterilized'];
$dog_3_birthdate = $_POST['dog_3_birthdate'];
$dog_3_rabies_immunization_date = $_POST['dog_3_rabies_immunization_date'];
$dog_3_bordetella_immunization_date = $_POST['dog_3_bordetella_immunization_date'];
$dog_3_dhlpp_immunization_date = $_POST['dog_3_dhlpp_immunization_date'];
$dog_3_services_basic_regular = $_POST['dog_3_services_basic_regular'];
$dog_3_services_basic_peak = $_POST['dog_3_services_basic_peak'];
$dog_3_services_delights_regular = $_POST['dog_3_services_delights_regular'];
$dog_3_services_delights_peak = $_POST['dog_3_services_delights_peak'];
$dog_3_walk_or_exercise = $_POST['dog_3_walk_or_exercise'];
$dog_3_services_doggy_day_lodge = $_POST['dog_3_services_doggy_day_lodge'];
$message = $_POST['message'];
$agree_to_terms_and_conditions = $_POST['agree_to_terms_and_conditions'];

// Page URLs
$url_form = getenv("http_referer");
$url_error_empty_fields = "error_empty_fields.html";
$url_error_invalid_fields = "error_invalid_fields.html";
$url_unknown_error = "error_unknown.html";
$url_success = "thank_you.html";

// Check for errors (empty fields)
if (empty($dropoff_date) || empty($pickup_date) || empty($first_name) || empty($last_name) || empty($email) || empty($address) || empty($city) || empty($state) || empty($zip) || empty($dog_bitten) || empty($lodging_plan) || empty($agree_to_terms_and_conditions)) {
	header("Location: $url_error_empty_fields");
	exit ;
	}

// Check for errors (invalid fields)
if ($dropoff_date == "MM/DD/YYYY" || $pickup_date == "MM/DD/YYYY") {
	header("Location: $url_error_invalid_fields");
	exit ;
	}

// "Sender Name" <email@address.com>
$sender = "\"" . $first_name . " " . $last_name . "\" <" . $email . ">";

// Recipient of email
$recipient = "my_email_address@my_domain.com";

// Script variables
$subject = "Dog Registration; " . $dropoff_date . " to " . $pickup_date;
$headers = "From: " . $sender . "\r\n";
$headers .= "Reply-To: " . $sender . "\r\n";
$headers .= "Return-Path: " . $sender . "\r\n";
$headers .= "CC: " . "" . "\r\n";
$headers .= "BCC: " . "" . "\r\n";
$message =
	"----------------------- Contact Info ------------------------\n" .
	"Customer ID #               " . $customer_id_number . "\n" .
	"Owner Name                  " . $first_name . " " . $last_name . "\n" .
	"Street Address              " . $address . "\n" .
	"City, State, Zip            " . $city . ", " . $state . "  " . $zip . "\n" .
	"Email Address               " . $email . "\n" .
	"Daytime Phone #             " . $daytime_phone . "\n" .
	"Evening Phone #             " . $evening_phone . "\n" .
	"Mobile Phone #              " . $mobile_phone . "\n" .
	"\n" .
	"------------------- Preferred Veternarian -------------------\n" .
	"Doctor Name                 " . $doctor_name . "\n" .
	"Clinic Name                 " . $clinic_name . "\n" .
	"Clinic Phone #              " . $clinic_phone . "\n" .
	"Has dog bitten someone?     " . $dog_bitten . "\n" .
	"\n" .
	"-------------------- Reservation Details --------------------\n" .
	"Dog Stay                          " . $dropoff_date . " to " . $pickup_date . "\n" .
	"Plan & Suite                      " . $lodging_plan . "\n" .
	"Dog 1 Services, Basic             " . $dog_1_services_basic_regular . "\n" .
	"Dog 1 Services, Basic (Peak)      " . $dog_1_services_basic_peak . "\n" .
	"Dog 1 Services, Delights          " . $dog_1_services_delights_regular . "\n" .
	"Dog 1 Services, Delights (Peak)   " . $dog_1_services_delights_peak . "\n" .
	"Dog 1 Services, Doggy Day Lodge   " . $dog_1_services_doggy_day_lodge . "\n" .
	"Dog 2 Services, Basic             " . $dog_2_services_basic_regular . "\n" .
	"Dog 2 Services, Basic (Peak)      " . $dog_2_services_basic_peak . "\n" .
	"Dog 2 Services, Delights          " . $dog_2_services_delights_regular . "\n" .
	"Dog 2 Services, Delights (Peak)   " . $dog_2_services_delights_peak . "\n" .
	"Dog 2 Services, Doggy Day Lodge   " . $dog_2_services_doggy_day_lodge . "\n" .
	"Dog 3 Services, Basic             " . $dog_3_services_basic_regular . "\n" .
	"Dog 3 Services, Basic (Peak)      " . $dog_3_services_basic_peak . "\n" .
	"Dog 3 Services, Delights          " . $dog_3_services_delights_regular . "\n" .
	"Dog 3 Services, Delights (Peak)   " . $dog_3_services_delights_peak . "\n" .
	"Dog 3 Services, Doggy Day Lodge   " . $dog_3_services_doggy_day_lodge . "\n" .
	"\n" .
	"--------------------------- Dog 1 ---------------------------\n" .
	"Name                        " . $dog_1_name . "\n" .
	"Breed                       " . $dog_1_breed . "\n" .
	"Sex                         " . $dog_1_sex . "\n" .
	"Sterilized                  " . $dog_1_sterilized . "\n" .
	"Birth Date                  " . $dog_1_birthdate . "\n" .
	"Rabies Immunization         " . $dog_1_rabies_immunization_date . "\n" .
	"Bordetella Immunization     " . $dog_1_bordetella_immunization_date . "\n" .
	"DHLPP Immunization          " . $dog_1_dhlpp_immunization_date . "\n" .
	"\n" .
	"--------------------------- Dog 2 ---------------------------\n" .
	"Name                        " . $dog_2_name . "\n" .
	"Breed                       " . $dog_2_breed . "\n" .
	"Sex                         " . $dog_2_sex . "\n" .
	"Sterilized                  " . $dog_2_sterilized . "\n" .
	"Birth Date                  " . $dog_2_birthdate . "\n" .
	"Rabies Immunization         " . $dog_2_rabies_immunization_date . "\n" .
	"Bordetella Immunization     " . $dog_2_bordetella_immunization_date . "\n" .
	"DHLPP Immunization          " . $dog_2_dhlpp_immunization_date . "\n" .
	"\n" .
	"--------------------------- Dog 3 ---------------------------\n" .
	"Name                        " . $dog_3_name . "\n" .
	"Breed                       " . $dog_3_breed . "\n" .
	"Sex                         " . $dog_3_sex . "\n" .
	"Sterilized                  " . $dog_3_sterilized . "\n" .
	"Birth Date                  " . $dog_3_birthdate . "\n" .
	"Rabies Immunization         " . $dog_3_rabies_immunization_date . "\n" .
	"Bordetella Immunization     " . $dog_3_bordetella_immunization_date . "\n" .
	"DHLPP Immunization          " . $dog_3_dhlpp_immunization_date . "\n" .
	"\n" .
	"---------------- Comments & Additional Notes ----------------\n" .
	$message . "\n" .
	"\n" .
	"----------------------- Miscellaneous -----------------------\n" .
	"Agreed to terms?            " . $agree_to_terms_and_conditions . "\n" .
	"This message was sent from:\n" .
	$url_form;

// Send email
if (mail($recipient,$subject,$message,$headers)){
	header("Location: $url_success");
	} else {
	header("Location: $url_unknown_error");
	}

?>
```
Basically, when I don't have the [] brackets attached to the names of each checkbox on my form, I only get the last checkbox that was checked in my email.  I need all of the items that are checked, not just one!  In its current form, the only result I get in my email is "Array".

I have since added the [] brackets, and toyed around with the serialize / unserialize PHP functions, and _can_ produce a result that looks like:

```
a:3:{i:0;s:11:"Daily Brush";i:1;s:14:"Afternoon Walk";i:2;s:11:"Medications";}
```
...but, I don't know how to make that useable.  Any help would be awesome!


----------



## gooseman (May 31, 2005)

Hi,

I wouldn't use an array for the checkboxes. Just name each checkbox with a unique name i.e. service_1, service_2, service_3 etc.

Then each checkbox will go through to the php script with it's own name.

If that doesn't work, you've completely lost me!


----------



## MDLarson (May 31, 2005)

Hey, thanks for the tip, but I would rather have each checkbox values separated by commas on *one* line in my email (which _may_ text-wrap), as opposed to having to hard code each service into my email template (which _will_ grow to a very large email).


----------



## ElDiabloConCaca (May 31, 2005)

I'm no PHP guru, but it seems like the checkboxes are being returned as an array -- so you may need to access the elements of the array, and not the array directly.

Perhaps a loop that iterates through the array, checking for NULL entries (checkboxes that are unchecked) and non-NULL entries (checkboxes that are checked) and then print them comma-delimited.


----------



## sonjay (May 31, 2005)

```
foreach ($_POST['dog_1_services_basic_regular'] as $service_basic) {			
     $message .= "Service: $service_basic\n";
}
```


----------



## MDLarson (Jun 1, 2005)

Awesome!  It's working!    I took sonjay's code and modified it to more of what ElDiablo was thinking, and I am sure I can come up with a nice solution.  Thanks guys.  I will try to remember to post the PHP code when I'm all done.


----------



## MDLarson (Jun 1, 2005)

Hmm, I hit another road bump.  Here's the code:
	
	



```
<?php

// Variables from form input
$customer_id_number = $_POST['customer_id_number'];
$dropoff_date = $_POST['dropoff_date'];
$pickup_date = $_POST['pickup_date'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$email = $_POST['email'];
$daytime_phone = $_POST['daytime_phone'];
$evening_phone = $_POST['evening_phone'];
$mobile_phone = $_POST['mobile_phone'];
$doctor_name = $_POST['doctor_name'];
$clinic_name = $_POST['clinic_name'];
$clinic_phone = $_POST['clinic_phone'];
$dog_bitten = $_POST['dog_bitten'];
$lodging_plan = $_POST['lodging_plan'];
$dog_1_name = $_POST['dog_1_name'];
$dog_1_breed = $_POST['dog_1_breed'];
$dog_1_sex = $_POST['dog_1_sex'];
$dog_1_sterilized = $_POST['dog_1_sterilized'];
$dog_1_birthdate = $_POST['dog_1_birthdate'];
$dog_1_rabies_immunization_date = $_POST['dog_1_rabies_immunization_date'];
$dog_1_bordetella_immunization_date = $_POST['dog_1_bordetella_immunization_date'];
$dog_1_dhlpp_immunization_date = $_POST['dog_1_dhlpp_immunization_date'];
$dog_1_walk_or_exercise = $_POST['dog_1_walk_or_exercise'];
$dog_2_name = $_POST['dog_2_name'];
$dog_2_breed = $_POST['dog_2_breed'];
$dog_2_sex = $_POST['dog_2_sex'];
$dog_2_sterilized = $_POST['dog_2_sterilized'];
$dog_2_birthdate = $_POST['dog_2_birthdate'];
$dog_2_rabies_immunization_date = $_POST['dog_2_rabies_immunization_date'];
$dog_2_bordetella_immunization_date = $_POST['dog_2_bordetella_immunization_date'];
$dog_2_dhlpp_immunization_date = $_POST['dog_2_dhlpp_immunization_date'];
$dog_2_walk_or_exercise = $_POST['dog_2_walk_or_exercise'];
$dog_3_name = $_POST['dog_3_name'];
$dog_3_breed = $_POST['dog_3_breed'];
$dog_3_sex = $_POST['dog_3_sex'];
$dog_3_sterilized = $_POST['dog_3_sterilized'];
$dog_3_birthdate = $_POST['dog_3_birthdate'];
$dog_3_rabies_immunization_date = $_POST['dog_3_rabies_immunization_date'];
$dog_3_bordetella_immunization_date = $_POST['dog_3_bordetella_immunization_date'];
$dog_3_dhlpp_immunization_date = $_POST['dog_3_dhlpp_immunization_date'];
$dog_3_walk_or_exercise = $_POST['dog_3_walk_or_exercise'];
$message = $_POST['message'];
$agree_to_terms_and_conditions = $_POST['agree_to_terms_and_conditions'];
foreach ($_POST['dog_1_services_basic_regular'] as $dog_1_services_basic_regular) {
     $all_dog_1_services .= "\n+Service (Basic / Regular)    $dog_1_services_basic_regular";
}
foreach ($_POST['dog_1_services_basic_peak'] as $dog_1_services_basic_peak) {
     $all_dog_1_services .= "\n+Service (Basic / Peak)       $dog_1_services_basic_peak";
}
foreach ($_POST['dog_1_services_delights_regular'] as $dog_1_services_delights_regular) {
     $all_dog_1_services .= "\n+Service (Delights / Regular) $dog_1_services_delights_regular";
}
foreach ($_POST['dog_1_services_delights_peak'] as $dog_1_services_delights_peak) {
     $all_dog_1_services .= "\n+Service (Delights / Peak)    $dog_1_services_delights_peak";
}
foreach ($_POST['dog_1_services_doggy_day_lodge'] as $dog_1_services_doggy_day_lodge) {
     $all_dog_1_services .= "\n+Service (Doggy Day Lodge)    $dog_1_services_doggy_day_lodge";
}
foreach ($_POST['dog_2_services_basic_regular'] as $dog_2_services_basic_regular) {
     $all_dog_2_services .= "\n+Service (Basic / Regular)    $dog_2_services_basic_regular";
}
foreach ($_POST['dog_2_services_basic_peak'] as $dog_2_services_basic_peak) {
     $all_dog_2_services .= "\n+Service (Basic / Peak)       $dog_2_services_basic_peak";
}
foreach ($_POST['dog_2_services_delights_regular'] as $dog_2_services_delights_regular) {
     $all_dog_2_services .= "\n+Service (Delights / Regular) $dog_2_services_delights_regular";
}
foreach ($_POST['dog_2_services_delights_peak'] as $dog_2_services_delights_peak) {
     $all_dog_2_services .= "\n+Service (Delights / Peak)    $dog_2_services_delights_peak";
}
foreach ($_POST['dog_2_services_doggy_day_lodge'] as $dog_2_services_doggy_day_lodge) {
     $all_dog_2_services .= "\n+Service (Doggy Day Lodge)    $dog_2_services_doggy_day_lodge";
}
foreach ($_POST['dog_3_services_basic_regular'] as $dog_3_services_basic_regular) {
     $all_dog_3_services .= "\n+Service (Basic / Regular)    $dog_3_services_basic_regular";
}
foreach ($_POST['dog_3_services_basic_peak'] as $dog_3_services_basic_peak) {
     $all_dog_3_services .= "\n+Service (Basic / Peak)       $dog_3_services_basic_peak";
}
foreach ($_POST['dog_3_services_delights_regular'] as $dog_3_services_delights_regular) {
     $all_dog_3_services .= "\n+Service (Delights / Regular) $dog_3_services_delights_regular";
}
foreach ($_POST['dog_3_services_delights_peak'] as $dog_3_services_delights_peak) {
     $all_dog_3_services .= "\n+Service (Delights / Peak)    $dog_3_services_delights_peak";
}
foreach ($_POST['dog_3_services_doggy_day_lodge'] as $dog_3_services_doggy_day_lodge) {
     $all_dog_3_services .= "\n+Service (Doggy Day Lodge)    $dog_3_services_doggy_day_lodge";
}

// Page URLs
$url_form = getenv("http_referer");
$url_error_empty_fields = "error_empty_fields.html";
$url_error_invalid_fields = "error_invalid_fields.html";
$url_unknown_error = "error_unknown.html";
$url_success = "thank_you.html";

// Check for errors (empty fields)
if (empty($dropoff_date) || empty($pickup_date) || empty($first_name) || empty($last_name) || empty($email) || empty($address) || empty($city) || empty($state) || empty($zip) || empty($dog_bitten) || empty($lodging_plan) || empty($agree_to_terms_and_conditions)) {
	header("Location: $url_error_empty_fields");
	exit ;
	}

// Check for errors (invalid fields)
if ($dropoff_date == "MM/DD/YYYY" || $pickup_date == "MM/DD/YYYY") {
	header("Location: $url_error_invalid_fields");
	exit ;
	}

// "Sender Name" <email@address.com>
$sender = "\"" . $first_name . " " . $last_name . "\" <" . $email . ">";

// Recipient of email
$recipient = "MY_EMAIL@MY_DOMAIN.com";

// Script variables
$subject = "Dog Registration; " . $dropoff_date . " to " . $pickup_date;
$headers = "From: " . $sender . "\r\n";
$headers .= "Reply-To: " . $sender . "\r\n";
$headers .= "Return-Path: " . $sender . "\r\n";
$headers .= "CC: " . "" . "\r\n";
$headers .= "BCC: " . "" . "\r\n";
$message =
	"=== Contact Info ========================================================================\n" .
	"Customer ID #                 " . $customer_id_number . "\n" .
	"Owner Name                    " . $first_name . " " . $last_name . "\n" .
	"Street Address                " . $address . "\n" .
	"City, State, Zip              " . $city . ", " . $state . "  " . $zip . "\n" .
	"Email Address                 " . $email . "\n" .
	"Daytime Phone #               " . $daytime_phone . "\n" .
	"Evening Phone #               " . $evening_phone . "\n" .
	"Mobile Phone #                " . $mobile_phone . "\n" .
	"\n" .
	"=== Preferred Veternarian ===============================================================\n" .
	"Doctor Name                   " . $doctor_name . "\n" .
	"Clinic Name                   " . $clinic_name . "\n" .
	"Clinic Phone #                " . $clinic_phone . "\n" .
	"Has dog bitten someone?       " . $dog_bitten . "\n" .
	"\n" .
	"=== Reservation Details =================================================================\n" .
	"Dog Stay                      " . $dropoff_date . " to " . $pickup_date . "\n" .
	"Plan & Suite                  " . $lodging_plan . "\n" .
	"\n" .
	"=== Dog 1 ===============================================================================\n" .
	"Name                          " . $dog_1_name . "\n" .
	"Breed                         " . $dog_1_breed . "\n" .
	"Sex                           " . $dog_1_sex . "\n" .
	"Sterilized                    " . $dog_1_sterilized . "\n" .
	"Birth Date                    " . $dog_1_birthdate . "\n" .
	"Rabies Immunization           " . $dog_1_rabies_immunization_date . "\n" .
	"Bordetella Immunization       " . $dog_1_bordetella_immunization_date . "\n" .
	"DHLPP Immunization            " . $dog_1_dhlpp_immunization_date . $all_dog_1_services . "\n" .
	"Walk or Exercise              " . $dog_1_walk_or_exercise . " (only if included in plan)\n" .
	"\n" .
	"=== Dog 2 ===============================================================================\n" .
	"Name                          " . $dog_2_name . "\n" .
	"Breed                         " . $dog_2_breed . "\n" .
	"Sex                           " . $dog_2_sex . "\n" .
	"Sterilized                    " . $dog_2_sterilized . "\n" .
	"Birth Date                    " . $dog_2_birthdate . "\n" .
	"Rabies Immunization           " . $dog_2_rabies_immunization_date . "\n" .
	"Bordetella Immunization       " . $dog_2_bordetella_immunization_date . "\n" .
	"DHLPP Immunization            " . $dog_2_dhlpp_immunization_date . $all_dog_2_services . "\n" .
	"Walk or Exercise              " . $dog_2_walk_or_exercise . " (only if included in plan)\n" .
	"\n" .
	"=== Dog 3 ===============================================================================\n" .
	"Name                          " . $dog_3_name . "\n" .
	"Breed                         " . $dog_3_breed . "\n" .
	"Sex                           " . $dog_3_sex . "\n" .
	"Sterilized                    " . $dog_3_sterilized . "\n" .
	"Birth Date                    " . $dog_3_birthdate . "\n" .
	"Rabies Immunization           " . $dog_3_rabies_immunization_date . "\n" .
	"Bordetella Immunization       " . $dog_3_bordetella_immunization_date . "\n" .
	"DHLPP Immunization            " . $dog_3_dhlpp_immunization_date . $all_dog_3_services . "\n" .
	"Walk or Exercise              " . $dog_3_walk_or_exercise . " (only if included in plan)\n" .
	"\n" .
	"=== Comments & Additional Notes =========================================================\n" .
	$message . "\n" .
	"\n" .
	"=== Miscellaneous =======================================================================\n" .
	"Agreed to terms?              " . $agree_to_terms_and_conditions . "\n" .
	"This message was sent from:\n" .
	$url_form;

// Send email
if (mail($recipient,$subject,$message,$headers)){
	header("Location: $url_success");
	} else {
	header("Location: $url_unknown_error");
	}

?>
```
Basically, when I fail to select at least one checkbox in one of the service sections, I get an error message kinda like...
*Warning: Invalid argument supplied for foreach() in /home/stone10/public_html/contact/registration_dog/emailer.php on line 54*
How can I modify my script to account for empty values?


----------



## sonjay (Jun 1, 2005)

Oh, that's easy enough to fix. If none of the checkboxes is checked, that POST variable isn't set, so there's nothing to loop through -- thus, the error you're getting. So, wrap the whole if statement inside another that checks to see if the variable has been set:


```
if ( isset($_POST['dog_1_services_basic_regular']) ) {
    // your original code here
}
```


Now you're checking to see if it's set before you try to loop through it.

You could even do an if/else to do something if they didn't check any of the service boxes:

```
if ( isset($_POST['dog_1_services_basic_regular']) ) {
     // your original code here
} else {
    // echo "No services wanted" -- or whatever
}
```


----------



## MDLarson (Jun 3, 2005)

Awesome; I got it working well.  I am definitely tipping to the right as far as left-brain / right-brain orientation goes... programming comes after GUI for me.  Thanks for all the help!


----------

