How to Pass an Array of Checked/Unchecked Checkbox Values to PHP Email Generator

PHP Email Send value of checkbox Yes if checked No if Unchecked

If you want to send each in a seperate email:

foreach($_POST['boxfan'] as $boxfan){
if(isset($boxfan)){
$message = "Yes";
mail($to, $subject, $message);
} else{
$message = "No";
mail($to, $subject, $message);
}
}

But if you want to send both in one email:

$message = null;
foreach($_POST['boxfan'] as $boxfan){
if(isset($boxfan)){
$message .= "Yes\r\n";
} else{
$message .= "No\r\n";
}
}
mail($to, $subject, $message);

Include also unchecked boxes in the POST variable - multiple checkbox

Here is the solution I used ( based on PeeHaa comment):

        if(!empty($_POST['check_list'])) {
foreach ($com as $co) {

if (in_array($co->comment_ID,$_POST['check_list']))
update_comment_meta($co->comment_ID, 'consider', 1);

else
update_comment_meta($co->comment_ID, 'consider', 0);
}
}

In fact POST variable works like this with checkboxes, so the simple way is to use server side language to know what are values not sent via POST.

Thank you for your time.

Passing an HTML Checkbox Array (w/ Empty Values) to PHP

Checkbox values only get sent if they are checked.

The checkbox name does not have to be an 'array' format, unless there are lots of them. In this case, each one will need a different value.

Not sure what all your code is doing. You do not seem to be checking anywhere for if ( is_array ( $_POST['cb'] ) ) { ...



Related Topics



Leave a reply



Submit