$_POST 禁用选择

$_POST for disabled select($_POST 禁用选择)
本文介绍了$_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和

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)