Submit an HTML form with empty checkboxes
I've used this technique from time to time:
<input type="hidden" name="the_checkbox" value="0" /><input type="checkbox" name="the_checkbox" value="1" />
note: This gets interpreted differently in different server-side languages, so test and adjust if necessary. Thanks to SimonSimCity for the tip.
Unchecked radio or checkbox elements are not submitted as they are not considered as successful. So you have to check if they are sent using the isset
or empty
function.
if (isset($_POST['checkbox'])) { // checkbox has been checked}