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
Composer:How to Add a Dependency Without Network Connection
Visits Counter Without Database with PHP
PHP Resize Image on or Before Upload
Facebook Like Custom Profile Url PHP
Create an Assoc Array with Equal Keys and Values from a Regular Array
PHP Using Regex to Get Substring of a String
PHP Fatal Error: Call to Undefined Function Imagettftext()
PHP Gd: How to Get Imagedata as Binary String
Include Just Files in Scandir Array
Symfony2 & Doctrine: Create Custom SQL-Query
Php: Fastest Way to Check for Invalid Characters (All But A-Z, A-Z, 0-9, #, -, ., $)
Save CSV Files into MySQL Database
Customizing My-Account Addresses Fields in Woocommerce 3
Adding an Additional Custom Field in Woocommerce Edit Account Page
PHP Explode Array Then Loop Through Values and Output to Variable