POST unchecked HTML checkboxes

The solution I liked the most so far is to put a hidden input with the same name as the checkbox that might not be checked. I think it works so that if the checkbox isn’t checked, the hidden input is still successful and sent to the server but if the checkbox is checked it will override the hidden input before it. This way you don’t have to keep track of which values in the posted data were expected to come from checkboxes.

<form>
  <input type="hidden" value="0" name="selfdestruct">
  <input type="checkbox" value="1" name="selfdestruct">
</form>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)