cee*_*yoz 93
我不时使用这种技术:
<input type="hidden" name="the_checkbox" value="0" />
<input type="checkbox" name="the_checkbox" value="1" />
注意:这被解释不同在不同的服务器端语言,所以测试,必要时调整.感谢SimonSimCity的提示.
Gum*_*mbo 41
未提供未选中的广播或复选框元素,因为它们不被视为成功.所以你必须检查它们是否是使用isset或empty函数发送的.
if (isset($_POST['checkbox'])) {
    // checkbox has been checked
}
未检查的复选框不会在POST数据中发送.你应该检查它是否为空:
if (empty($_POST['myCheckbox']))
     ....
else
     ....
小智 5
这是一个使用javascript的简单解决方法:
在提交包含复选框的表单之前,将"关闭"设置为0并检查它们以确保它们提交.例如,这适用于复选框数组.
/////示例//////
给出一个id ="formId"的表单
<form id="formId" onSubmit="return formSubmit('formId');" method="POST" action="yourAction.php">
<!--  your checkboxes here . for example: -->
<input type="checkbox" name="cb[]" value="1" >R
<input type="checkbox" name="cb[]" value="1" >G
<input type="checkbox" name="cb[]" value="1" >B
</form>
<?php
if($_POST['cb'][$i] == 0) {
    // empty
} elseif ($_POST['cb'][$i] == 1) {
    // checked
} else {
    // ????
}
?>
<script>
function formSubmit(formId){
var theForm = document.getElementById(formId); // get the form
var cb = theForm.getElementsByTagName('input'); // get the inputs
for(var i=0;i<cb.length;i++){ 
    if(cb[i].type=='checkbox' && !cb[i].checked)  // if this is an unchecked checkbox
    {
       cb[i].value = 0; // set the value to "off"
       cb[i].checked = true; // make sure it submits
    }
}
return true;
}
</script>