How do I require at least one checkbox to be checked. I have a form with text fields and checkboxes that is emailed.
Here is the html for the checkbox section...
<td height="24">
<input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox1">
Checkbox 1 </td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td><input name="checkbox2" type="checkbox" id="checkbox2" value="checkbox2">
Checkbox 2</td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td><input name="checkbox3" type="checkbox" id="checkbox3" value="checkbox3">
Checkbox 3</td>
</tr>
<tr>
<td align="right" valign="middle"> </td>
<td><input name="checkbox4" type="checkbox" id="checkbox4" value="checkbox4">
Checkbox 4</td>
Here is the php for my mail code...
<?php
// check to see if a name was entered
if (!$_POST['First_Name'])
// if not, add that error to our array
$errors[] = "First name is required";
if (!$_POST['Last_Name'])
// if not, add that error to our array
$errors[] = "Last name is required";
// if there are any errors, display them
if (count($errors)>0){
echo "<strong>ERROR:<br>\n";
foreach($errors as $err)
echo "$err<br>\n";
} else {
// no errors, so we build our message
$first_name = stripslashes($_POST['First_Name']);
$last_name = stripslashes($_POST['Last_Name']);
$address = ($_POST['Address']);
$city = ($_POST['City']);
$state = ($_POST['State']);
$zip = ($_POST['ZIP_Code']);
$phone = ($_POST['Phone']);
$email = stripslashes($_POST['Email']);
$checkbox1=($_POST['checkbox1'])?"Yes":"No";
$checkbox2=($_POST['checkbox2'])?"Yes":"No";
$checkbox3=($_POST['checkbox3'])?"Yes":"No";
$checkbox4=($_POST['checkbox4'])?"Yes":"No";
$msg.="\n$checkbox1\n$checkbox2\n$checkbox3\n$checkbox4";
$comments = stripslashes($_POST['MsgBody']);
//the mailing part
$to = 'email@gmail.com';
$subject = 'Email Form';
$msg = "Name: $first_name $last_name\n\n"."Address: $address\n\n".
"City: $city\n\n"."State: $state\n\n"
."ZIP Code: $zip\n\n"."Phone: $phone\n\n"."Email: $email\n\n"
."Checkbox 1: $checkbox1\n\n"."Checkbox 2: $checkbox2\n\n"
."Checkbox 3: $checkbox3\n\n"."Checkbox 4: $checkbox4\n\n"
."Comments: $comments\n\n";
;
if (mail($to, $subject, $msg)){
echo "<p>Form Sent!</p>";
echo nl2br($msg);
} else
echo "An unknown error occurred.";
}
?>
What code do I use for this and where to I put it in the process.php?
Thanks!