Skip to content Skip to sidebar Skip to footer

How To Send All Checkboxes In Post?

I have 10 checkboxes in a form. Only checked checkboxes are sending to POST. How to send all checkboxes to POST, beacouse I want to do instruction for changed to checked and change

Solution 1:

Only checked checkboxes are sent. A common strategy is to set hidden inputs with the same name and the default unchecked value. Just make sure the checkbox input comes after the hidden input:

<inputtype="hidden" name="cb" value="0">
<inputtype="checkbox" name="cb" value="1">

Then there will always be a $_POST['cb'] with value 0 for not checked and value 1 for checked.

Solution 2:

As I already stated in a comment, the browser will only send the checked checkboxes and will never send all checkboxes. What you can do is to check with PHP if the checkbox is present in the $_POST or $_GET variable and act according to the present state.

If you dynamically generate the checkboxes with a PHP script, you can make a hidden box with a serialized array with all the checkbox names to check and then you can only loop through it and check their states later on in the validation script.

Since you didn't provide any code I can't help you with it or make any improvements.

Post a Comment for "How To Send All Checkboxes In Post?"