samedi 6 juin 2015

Why we cannot POST unchecked checkbox?

I've a form with around 80 checkboxes and all of them will be checked by default. The user will only uncheck the unwanted items, so I was looking for unchecked checkbox elements in the POST. However, POST only holds values of checked ones.

After searching a bit, I have found a workaround for my situation: this question

The workaround:

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

Using this I am able to get values of hidden field and thus my purpose is fulfilled.

But the important question is why is this not a default feature? I have found valid reasons for any technical thing that sounds weird the first time. But for this (cannot post unchecked checkbox) I am still curious to know the reason.

I would appreciate if anyone can shed light on this topic.




Aucun commentaire:

Enregistrer un commentaire