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
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.
Yes, and most application servers will collect the matching elements and concatenate them with commas, such that a form like this:
<html>
<form method="get" action="http://myhost.com/myscript/test.asp">
<input type="hidden" name="myHidden" value="1">
<input type="hidden" name="myHidden" value="2">
<input type="hidden" name="myHidden" value="3">
<input type="submit" value="Submit">
</form>
</html>
... would resolve to a URL (in the GET case -- POST would work the same way, though) like this:
http://myhost.com/myscript.asp?myHidden=1&myHidden=2&myHidden=3
... and would be exposed to you in code like this: (e.g., following something like Response.Write(Request.QueryString("myHidden")):
1, 2, 3
So to grab the values, you'd just split the string and access them as an array (or whatever's comparable in your language of choice).
(Should be clarified: In PHP, it's slightly different (as Johnathan points out, bracket notation exposes the items as an array to your PHP code), but ASP, ASP.NET, and ColdFusion all expose the values as a comma-separated list. So yes, the duplicate naming is completely valid.)