Include also unchecked boxes in the POST variable - multiple checkbox Include also unchecked boxes in the POST variable - multiple checkbox wordpress wordpress

Include also unchecked boxes in the POST variable - multiple checkbox


sending unchecked value to post is somewhat not that easy.Better solution is that you name checkbox in a way using which you can easily iterate over them in post page.

Use hidden input along with checkbox.Checkbox prioritize over hidden input.

<form>  <input type='hidden' value='0' name='check_box_con'>  <input type='checkbox' value='1' name='check_box_con'></form>

Now after submit, as both have same name , check_box_con will show hidden field value if unchecked , else will override and show original.

For more seePost the checkboxes that are unchecked


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.