PHP $_POST、$_GET 和 $_REQUEST 键
是否有过这样的情况(比如某些奇怪的浏览器),表单输入字段的 id 成为 $_POST、$_GET 或 $_REQUEST 中的键,而不是字段的名称?
我们在 ID 与名称不匹配的字段中遇到了问题。更改 ID 以匹配似乎可以解决该问题。问题纯粹是 PHP 解析;不涉及 JS。
巧合?
Google 没有返回这样的东西...
函数(抱歉,旧的 php4 代码)生成该字段。这是它的一部分
echo "<select name=\"$varName";
echo "_dd\" id=\"$varName";
echo "e_dd\">\n";
从最后一行删除“e”显然修复了它。这不是我自己做的;这里有人告诉我它解决了问题。它并没有破坏每个日期字段,这似乎是一个间歇性问题。这就是为什么我立即想到了一些奇怪的浏览器怪癖。
Is there ever a case (like some quirky browser) where a form input field's id becomes the key in $_POST, $_GET or $_REQUEST, instead of the field's name?
We were having trouble with a field where the ID didn't match the name. Changing the ID to match appeared to fix the problem. The issue was purely PHP parsing; no JS involved.
Coincidence?
Google returns no such thing...
A function (sorry, old php4 code) generates the field. Here's part of it
echo "<select name=\"$varName";
echo "_dd\" id=\"$varName";
echo "e_dd\">\n";
Removing the 'e' from that last line apparently fixed it. I didn't do it myself; someone here told me it fixed the issue. It didn't break every date field, it seemed to be an intermittent problem. That's why I immediately thought of some strange browser quirk.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 XHTML 1.1 strict 中,id 已取代 name,并且 name 已被弃用。
如果您的 XHTML 是使用 HTTP Content-Type application/xhtml+xml 发送的(根据标准,它必须如此),那么按照该标准到 Tee 的浏览器很可能会使用PHP 中填充 $_POST 的是 ids,而不是名称。
http://www.codingforums.com/archive/index.php/ t-29229.html
请参阅 XHTML 1.1 规范:http:// /www.w3.org/TR/xhtml-modularization/abstract_modules.html
名称属性仅允许在 a、applet、frame、iframe 和 map 元素中使用。任何其他恰好有名称的元素都必须有一个同名的 id。
In XHTML 1.1 strict, id has replaced name and name is deprecated.
If your XHTML is sent using the HTTP Content-Type application/xhtml+xml (which according to standards, it must), then it is probable that a browser that goes by the standard to a Tee would use ids to populate $_POST in PHP, not name.
http://www.codingforums.com/archive/index.php/t-29229.html
See the XHTML 1.1 spec: http://www.w3.org/TR/xhtml-modularization/abstract_modules.html
Name attributes are only allowed in a, applet, frame, iframe and map elements. And any other element that just happens to have a name, must have an id of the same name.
不,这是
name
属性命名控制字段:No, it’s the
name
attribute that names the control field:干净的代码就是好代码:)。你能验证这不起作用吗?
如果能看到生成的 html 就好了。
Clean code is nice code :). Can you verify this doesn't work?
It would be good to see the generated html too.