我注意到 PHP 似乎只返回选中复选框的值.我想查看复选框列表,而不仅仅是选中复选框的值.有没有办法检测未选中框的变量?
I noticed that PHP seems to return only values of checked checkboxes. I would like to see a list of checkboxes, not just values of checked checkboxes. Is there a way to detect variables of unchecked boxes?
我问是因为我希望能够更新设置.例如,我有一些已被选中的选项,但如果用户决定取消选中某个选项,我需要知道未选中的值,以便我可以更新要禁用的选项.
I asked because I want to be able to update settings. For example, I have a few options that are already checked but if an user decides to uncheck an option, I need to know that unchecked value so I can update the option to be disabled.
我自己刚刚遇到了这个问题.我通过添加具有相同名称的重复 hidden 字段来解决它.当浏览器发送此信息时,第二个字段会覆盖第一个字段(因此请确保 hidden 字段排在最前面).
I just ran into this problem myself. I solved it by adding a duplicate hidden field with the same name. When the browser sends this information, the second field overrides the first (so ensure that the hidden field comes first).
<input type="hidden" name="foo" value="">
<input type="checkbox" name="foo" value="bar">
如果 checkbox 没有被选中,你会得到:
If the checkbox is not checked you get:
$_REQUEST[ 'foo' ] == ""
如果checkbox被选中,你会得到:
If the checkbox is checked you get:
$_REQUEST[ 'foo' ] == "bar"
这篇关于即使没有从 HTML 到 PHP 进行检查,我如何获取所有复选框变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
以编程方式将可下载文件添加到 Woocommerce 产品Add programmatically a downloadable file to Woocommerce products(以编程方式将可下载文件添加到 Woocommerce 产品)
获取今天 Woocommerce 中每种产品的总订单数Get today#39;s total orders count for each product in Woocommerce(获取今天 Woocommerce 中每种产品的总订单数)
在 WooCommerce 和电话字段验证问题中添加自定义注Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和电话字段验证问题中添加自定义注册字段
在 Woocommerce 简单产品中添加一个将更改价格的选Add a select field that will change price in Woocommerce simple products(在 Woocommerce 简单产品中添加一个将更改价格的选择字段)
在 WooCommerce 3 中将自定义列添加到管理产品列表Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中将自定义列添加到管理产品列表)
自定义结帐“下订单"按钮输出htmlCustomizing checkout quot;Place Orderquot; button output html(自定义结帐“下订单按钮输出html)