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:可以自动获取所有发布的数据并且取消选中多


- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01