$_POST for disabled select($_POST 禁用选择)
问题描述
<select class="txtbx1" name="country" disabled>
<option value='FR' >FRANCE</option><option value='CH' selected>SWITZERLAND</option>
</select>
上面的代码在一个方法是post的表单中
the above code is inside a form whose method is post
但是 echo $_POST['country']
没有显示任何东西..另一方面,如果我从 select $_POST['country']
中删除 disabled正确的结果
but echo $_POST['country']
is showing nothing.. on the other hand if I remove disabled from select $_POST['country']
is showing the correct result
推荐答案
这就是 disabled
属性的工作原理.当表单控件被禁用时,提交表单时将忽略该值,并且键不会出现在 $_POST
(或 $_GET
)中.
This is how the disabled
attribute works. When a form control is disabled, the value will be ignored when the form is submitted and the key will not be present in $_POST
(or $_GET
).
如果您希望该值出现在提交的数据中,但又不希望用户能够更改页面上的值(我想这就是您想要实现的),请使用 readonly="readonly"
而不是 disabled="disabled"
.
If you want the value to be present in the submitted data, but you don't want the user to be able to change the value on the page (which I imagine is what you are trying to acheive) use readonly="readonly"
instead of disabled="disabled"
.
编辑
元素没有
readonly
属性.上述信息仍然将适用于s和
s.
The <select>
element does not have a readonly
attribute. The above information still stands as it will work for <input>
s and <textarea>
s.
此处问题的解决方案是禁用选择并使用隐藏输入将值发送回服务器 - 例如
The solution to your problem here would be to disable the select and use a hidden input to send the value back to the server - e.g.
启用选择时:
<select class="txtbx1" name="country">
<!-- options here -->
</select>
...当它被禁用时:
<select class="txtbx1" name="country_disabled" disabled="disabled">
<!-- options here, with appropriate value having `selected="selected"` -->
</select>
<input type="hidden" name="country" value="value_of_field" />
这篇关于$_POST 禁用选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:$_POST 禁用选择


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