Force a checkbox to always submit, even when unchecked

Thanks to @Lazarus’ idea, also mentioned by @BalusC, you can add an additional control to the form:

<input type="hidden" name="checkbox1" value="off">
<input type="checkbox" name="checkbox1" value="on"> My checkbox

Checkbox and the hidden fields must have the same name. The hidden input is always submitted as a default value. If the checkbox is checked then also it’s submitted. So you have a list of 2 values for parameter “checkbox1”, that you have to treat at server side.

…maybe a <select> tag would be more handy.

Leave a Comment