Reputation: 3894
How well supported (if at all) is sending query parameters with the same name to various web servers? i.e.
<form ...>
<input name="a" value="va" />
<input name="a" value="vb" />
Will most servers interpret this as an array or will one of the values be clobbered? i.e. will $_REQUEST from PHP return an array when accessing "a"? Or will this just return one of the values? And do all (decent) web servers required to support these inputs and return an array?
Upvotes: 0
Views: 1682
Reputation: 57115
The answer purely depends on what framework you use. When queried for the value of a URL parameter, some frameworks return the first parameter of the given name. Some return the last parameter of that name. Others return a comma-delimited list of parameters of that name. Yet others return an array of strings of parameters of that name.
HTTP itself doesn't provide any guidance on uniqueness of parameter names, nor does it even define the format of the querystring. The a=b&c=d
syntax is merely a convention used by HTML Forms, but other formats are entirely legal and are indeed used in some scenarios.
Upvotes: 2
Reputation: 129817
According to the W3C HTML 4.01 spec, checkbox input controls at least are allowed to share the same name, in order to "allow users to select several values for the same property" (see section 17.2.1). For radio buttons, sharing the same name is actually required, in order to determine which ones belong to the same set. (This results in only one value being sent to the server, however.) The HTML 4 spec does not seem to say whether sharing a name is allowed for other input types, but it should work the same as for checkboxes.
The HTML 5 spec actually does say specifically that "Multiple controls can have the same name" in section 4.10.1.3. Given that HTML has been around for a long time and that the HTML 5 spec is not that different from 4, at least for forms, I think it is safe to say that most modern browsers/servers are going to handle this situation correctly and not clobber the values. The best way to find out for sure, of course, is to try it yourself on those browsers/servers you are concerned about.
Upvotes: 0