A couple questions for you all,
I am making a form with a group of checkboxes on it and I can't seem to get it to work the way I want it to. I've been digging around trying to find the solution here and elsewhere but it's not quite working the way I want it. Here is what my form looks like:
<form method="post" action="mail_accident_form_script.php">
//some other code goes here
<input type="checkbox" name="Accident_type[]" value="Vehicle" checked> Vehicle
<input type="checkbox" name="Accident_type[]" value="Personal"> Personal
<input type="checkbox" name="Accident_type[]" value="Property"> Property
<input type="checkbox" name="Accident_type[]" value="Other"> Other
//some more code goes here
</form>
now at the top of my mail_accident_form_script.php page I have this:
if ($POST['Accident_type'] == ""){
$accident_type = "None";
}
else{
$accident_type = implode(", ",$POST['Accident_type']);
}
and then I eventually include $accident_type in a mailer gets sent out. This code works great if one or more of the checkboxes are checked. If none of them are checked $accident_type gets mailed out as "none" which is what I want but I also get a this notice on my mail_accident_form_script.php:
Notice: Undefined index: Accident_type in c:\inetpub\GEG_Intranet\procedures\mail_accident_form_script.php on line 3
Is there any way to get rid of this message?
Another question, how do I manipulate the checkboxes as an array in the next page? As I understand, these check boxes are already in an array. I think I might be getting the syntax wrong however, as I can't manipulate them in the way I want to:
$limit = count($_POST['Accident_type']);
$loop_counter = 0;
while($loop_counter != ($limit-1)){
if ($_POST['Accident_type[$loop_counter]'] == "Vehicle"){
//do something
}
else{
$loop_counter++;
}
}
Somehow, I don't think this part is right
$_POST['Accident_type[$loop_counter]']
As you can probably tell, I'm a newbie, I'm an ASP developer just starting out with PHP so any help would be much appreciated.
Thanks in advance