unchecked checkbox not in $_POST

January 20th, 2009 § 1

Iamcam posted a good hack on his blog. It makes your unchecked checkboxes show up in the $_POST on the server.
It’s very simple and doesn’t need javascript.

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

If the checkbox is not checked then the value of the hidden input is submited, else the value of the checkbox.

Where Am I?

You are currently browsing entries tagged with $_POST at westworld: a webmasters best friend.