HTML 用户代理是否需要按特定顺序提交表单数据?

发布于 2024-12-23 15:27:04 字数 2190 浏览 0 评论 0原文

对于给定的 HTML 表单,是否需要用户代理以特定顺序构建提交请求?

我正在查看 HTML 4.0.1 规范,它似乎没有指定“成功控件”成为提交请求的一部分的顺序。 第 17.13.3 节,处理表单数据,指出:

当用户提交表单(例如,通过激活提交按钮)时,用户代理按如下方式处理它。

第一步:识别成功的控制

第二步:构建表单数据集

表单数据集控件名称/当前值 对构造成功控制

第三步:对表单数据集进行编码

然后根据 FORM 元素的 enctype 属性指定的内容类型对表单数据集进行编码。

第四步:提交编码后的表单数据集

在第二步中,表单数据集被描述为一个序列,因此其在步骤3中编码的顺序大概是固定的。但是,这引出了一个问题:表单数据集中成功控制的顺序是什么。

例如,给定以下 HTML 表单:

<form action="#" method="GET">
<input type="hidden" name="key1" value="value1" />
<div>
    <div>
        <input type="hidden" name="key2" value="value2" />
    </div>
    <input type="hidden" name="key3" value="value3" />
    <input type="submit" name="submit" value="Submit" />
</div>
<input type="hidden" name="key5" value="value5" />
</form>

表单数据集可以是

[ ("key1", "value1"), ("key2", "value2" ), ("key3", "value3"), ("提交", "提交"), ("key5", “值5”)]

(即 DOM 的深度优先搜索);或者

[ ("key1", "value1"), ("key5", "value5" ), ("key3", "value3"), ("提交", "提交"), ("key2", “值2”)]

(广度优先搜索);或者甚至是通过迭代随机哈希表中的控件名称/当前值对而产生的不确定顺序?

使用 IE 9 和 Firefox 9.0.1 测试此表单,似乎都使用深度优先搜索顺序。也许其他浏览器有所不同。问题是这个命令是否是在某个地方规定的。

For a given HTML form, is a user agent required to build the submit request in a particular order?

I was looking through the HTML 4.0.1 Specification and it doesn't seem to specify the order that "successful controls" become part of the request on submission. Section 17.13.3, Processing form data, states:

When the user submits a form (e.g., by activating a submit button), the user agent processes it as follows.

Step one: Identify the successful controls

Step two: Build a form data set

A form data set is a sequence of control-name/current-value pairs constructed from successful controls

Step three: Encode the form data set

The form data set is then encoded according to the content type specified by the enctype attribute of the FORM element.

Step four: Submit the encoded form data set

At step two, the form data set is described as a sequence, so the order in which it is encoded in Step 3 is presumably fixed. But, this begs the question of what the order of successful controls is in the form data set.

For example, given the following HTML form:

<form action="#" method="GET">
<input type="hidden" name="key1" value="value1" />
<div>
    <div>
        <input type="hidden" name="key2" value="value2" />
    </div>
    <input type="hidden" name="key3" value="value3" />
    <input type="submit" name="submit" value="Submit" />
</div>
<input type="hidden" name="key5" value="value5" />
</form>

Could the form data set be

[ ("key1", "value1"), ("key2", "value2"), ("key3", "value3"), ("submit", "Submit"), ("key5", "value5") ]

(I.e. a depth-first search of the DOM); or

[ ("key1", "value1"), ("key5", "value5"), ("key3", "value3"), ("submit", "Submit"), ("key2", "value2") ]

(A breadth-first search); or even a nondeterministic order resulting from iterating the control-name/current-value pairs in a randomized hashtable?

Testing this form with IE 9 and Firefox 9.0.1, it seems that both use the depth-first search order. Perhaps other browsers are different. The question is whether this order is prescribed somewhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

烧了回忆取暖 2024-12-30 15:27:04

如果您继续查看 HTML 规范的 17.13.4 部分,它声明默认内容类型是application/x-www-form-urlencoded。该内容类型的部分说:

控件名称/值按照它们在文档中出现的顺序列出。

这表明深度优先遍历并且似乎与您的浏览器测试一致。

If you continue to section 17.13.4 of the HTML spec, it states that the default content type is application/x-www-form-urlencoded. The section for that content type says:

The control names/values are listed in the order they appear in the document.

This would suggest a depth-first traversal and would seem to agree with your browser tests.

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