PHP $_POST、$_GET 和 $_REQUEST 键

发布于 2024-09-16 06:38:59 字数 446 浏览 2 评论 0原文

是否有过这样的情况(比如某些奇怪的浏览器),表单输入字段的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

喜爱纠缠 2024-09-23 06:38:59

在 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.

深爱成瘾 2024-09-23 06:38:59

不,这是 name 属性命名控制字段

控件的“控件名称”由其 name 属性给出。 FORM 元素中控件的 name 属性的范围是 FORM 元素。

No, it’s the name attribute that names the control field:

A control's "control name" is given by its name attribute. The scope of the name attribute for a control within a FORM element is the FORM element.

得不到的就毁灭 2024-09-23 06:38:59

干净的代码就是好代码:)。你能验证这不起作用吗?

echo "<select name='".$varName."_dd' id='".$varName."e_dd'>\n"; 

如果能看到生成的 html 就好了。

Clean code is nice code :). Can you verify this doesn't work?

echo "<select name='".$varName."_dd' id='".$varName."e_dd'>\n"; 

It would be good to see the generated html too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文