0

I know how to get all the check checkboxes by using this code

if ($_SERVER["REQUEST_METHOD"] == "POST"){
    if(!empty($_POST['arrsymbols'])){
       $checksymb = $_POST['arrsymbols'];
       foreach ($checksymb as  $selected){
           echo $selected;
       }
    }
}

but my problem is how to get all uncheck checkboxes in php. Thank you

  • Unchecked checkboxes are not send with the rest of the form data. So you can only go about it the other way around - compare the values that you do get (checked checkboxes) with a list of all checkboxes (like an array with the keys used.) – CBroe May 09 '17 at 14:51

1 Answers1

0

You would need an array of all checkbox names you have on your page and then you could loop through this array counting how many of the checkboxes are not a key in the array $_POST. Another solution would be to remove the names from the checkboxes and add them to hidden input which are updated by JS if the checkboxes change.
jQuery("input[type='checkbox']").change(function(){ jQuery(this).parent().find("input[type='hidden']").val(jQuery(this).prop("checked")); } This code assumes you have a container for each checkbox containing one checkbox and one hidden input.

Jonathan
  • 177
  • 1
  • 11