朋友你好我有麻烦。
我正在尝试使用此代码动态获取表单的变量和值,但是有一个无数的数字复选框,可能有或没有标记,我想知道我怎么能得到一个关闭或“0 “如果不是这个标签的复选框,这些数据已被使用.ajax和数据:
复选框的简短示例:
<input name="p-sis-0110-1" type="checkbox">
<input name="p-sis-0110-2" type="checkbox">
<input name="p-sis-0110-3" type="checkbox">
<input name="p-sis-0110-4" type="checkbox">
<input name="p-sis-0110-5" type="checkbox">
<input name="p-sis-0110-6" type="checkbox">
或
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
的Ajax:
.$("#formarea").serialize()
PHP:
foreach ($_POST as $key => $value){
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>"
}
我感谢任何帮助解决这个小困境。
答案 0 :(得分:2)
仅<&34; 成功&#34;控件已提交。未选中的复选框或单选按钮不是 成功&#34;。
您需要使用隐藏输入声明默认值。确保隐藏的输入位于复选框之前,因此如果选中该复选框,它将覆盖默认的隐藏输入,因为名称相同:
Ctrl+Z
要使用数组,您需要显式定义索引,使它们相同:
<input name="p-sis-0110-1" type="hidden" value="0">
<input name="p-sis-0110-1" type="checkbox" value="1">