HTML form with multiple hidden control elements of the same name

前端 未结 8 2094
-上瘾入骨i
-上瘾入骨i 2020-11-27 06:14

Is it legal to have an HTML form with more than one \"hidden\" control element with the same name? I expect to get the values of all of these elements at the server. If it i

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 06:27

    HTML5

    The non-normative section 4.10.1.3 Configuring a form to communicate with a server explicitly says that it is valid:

    Multiple controls can have the same name; for example, here we give all the checkboxes the same name, and the server distinguishes which checkbox was checked by seeing which values are submitted with that name — like the radio buttons, they are also given unique values with the value attribute.

    The normative version of this is simply that it is not forbidden anywhere, and the form submission algorithm says exactly what request should be generated:

    • no constraint is violated: https://www.w3.org/TR/html5/forms.html#constraints
    • multiple names get added to the "form data set" one after the other: https://www.w3.org/TR/html5/forms.html#constructing-form-data-set
    • encodings like application/x-www-form-urlencoded loop over the "form data set" and spit out multiple key=val https://www.w3.org/TR/html5/forms.html#url-encoded-form-data

提交回复
热议问题