: Is it valid to have multiple form input elements with the same name? Is it valid markup and is it valid to the HTML/HTTP spec? If I wanted to have <form> <input name="email" />
Is it valid markup and is it valid to the HTML/HTTP spec? If I wanted to have
<form>
<input name="email" />
<input name="email" />
<input name="email" />
</form>
is that valid?
More posts by @Murray155
2 Comments
Sorted by latest first Latest Oldest Best
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: www.w3.org/TR/html5/forms.html#constraints multiple names get added to the "form data set" one after the other: 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 www.w3.org/TR/html5/forms.html#url-encoded-form-data
As stated on SO:
The browsers are OK with it. However,
how the application library parses it
may vary.
Programs are supposed to group
identically named items together.
While the HTML specification doesn't
explicitly say this, it is implicitly
stated in the documentation on
checkboxes:
"Several checkboxes in a form may share
the same control name. Thus, for
example, checkboxes allow users to
select several values for the same
property."
On a side note, in PHP you can have form fields with the same name if you use PHP's arry syntax for the field name:
<form>
<input name="email[]" />
<input name="email[]" />
<input name="email[]" />
</form>
This will cause the browser to send over the form fields in a syntax that PHP will use to populate an array for these fields: $_REQUEST['email']. If you use PHP this is the preferred way to handle it.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.