$_POST 禁用选择 [英] $_POST for disabled select

查看:23
本文介绍了$_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".

编辑

s和