PHP: Possible to automatically get all POSTed data And Multiple checkbox unchecked?(PHP:可以自动获取所有发布的数据并且取消选中多个复选框?)
问题描述
朋友们好,我有麻烦了.
Hello friends i have a trouble.
我正在尝试使用此代码来动态获取表单的变量和值,但是有无数个数字复选框,可能标记也可能未标记,我想知道如何关闭或0" 如果这不是一个复选框标记,这些数据已被使用 .ajax 和数据:
I'm trying to use this code to get dynamically, variables and values of a form, but there is a countless number checkbox, which may or not marked, I would like to know how can I get an off or "0" in case not this a checkbox labeled, these data have been used .ajax and data:
复选框的简短示例:
<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">
阿贾克斯:
.$("#formarea").serialize()
PHP:
foreach ($_POST as $key => $value){
echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>"
}
感谢您帮助解决这个小困境.
I appreciate any help to solve this little dilemma.
推荐答案
仅提交成功"控件.未选中的复选框或单选按钮不是成功".
Only "successful" controls are submitted. An unchecked checkbox or radio button is not "successful".
您需要声明一个带有隐藏输入的默认值.确保隐藏输入出现在复选框之前,因此如果选中该复选框,它将覆盖默认隐藏输入,因为名称相同:
You need to declare a default value with a hidden input. Make sure the hidden input comes before the checkbox so if the checkbox is checked it will override the default hidden input since the names are the same:
<input name="p-sis-0110-1" type="hidden" value="0">
<input name="p-sis-0110-1" type="checkbox" value="1">
要使用数组,您需要明确定义索引,使它们相同:
To use an array you need to explicitly define the indexes so they are the same:
<input name="input[0]" type="hidden" value="0">
<input name="input[0]" type="checkbox" value="1">
这篇关于PHP:可以自动获取所有发布的数据并且取消选中多个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHP:可以自动获取所有发布的数据并且取消选中多
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何替换eregi() 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
