I have added a checkbox to a form that the user can dynamically add rows to. You can see the form here.
I use an array to pass the values for each row to a PHP emai
$mailing = array();
foreach($_POST as $v){
$mailing[] = trim(stripslashes($v));
}
To handle unchecked boxes it would be better to set each checkbox with a unique value:
or
Then have a list of the checkboxes:
$boxes = array(1,2,3);
$mailing = array();
$p = array_key_exists('mailing',$_POST) ? $_POST['mailing'] : array();
foreach($boxes as $v){
if(array_key_exists($v,$p)){
$mailing[$v] = trim(stripslashes($p[$v]));
}else{
$mailing[$v] = 'No';
}
}
print_r($mailing);
You could also use this with a number of checkboxes instead:
$boxes = 3;
$mailing = array();
$p = array_key_exists('mailing',$_POST) ? $_POST['mailing'] : array();
for($v = 0; $v < $boxes; $v++){
if(array_key_exists($v,$p)){
$mailing[$v] = trim(stripslashes($p[$v]));
}else{
$mailing[$v] = 'No';
}
}
print_r($mailing);