6 ms·
I don't think multiple fields with the same name is designed to be a normal mode of operation. If you actually want an array, use the [] suffix. But if you hav
by ajanuary 12y ago
I don't think multiple fields with the same name is designed to be a normal mode of operation. If you actually want an array, use the [] suffix.
But if you have a bug which produces a form with multiple fields with the same name, what should it do? I can think of two strategies: last one wins and the proposal.
Both are probably going to lead to things going wrong in the backend. At least with the proposal you:
A) can detect it with boilerplate that looks for arrays where you expect primitives.
B) figure out what the original data was if you need to try and manually repair it.
I'm sure we'll see lots of bad tutorials suggesting you just use the same field name to make an array though :(
- stephenr 12y agodo any server-side environments currently present an array/array-like structure from request parameters with duplicate names (and specifically without any kind of array indicator, like name[] in php requests for example)?
- tomchristie 12y agoSure, yes. In Python land for example Django and Flask both present the request parameters in a dictionary-like data structure that supports lookup of the complete list of values passed for a given name. Regular lookups will give you just a single value, but they also present an interface to get the complete list.
- griffindy 12y agojersey[0], the reference implementation of JAX-RS[1] does this if you specify an incoming query string parameter as a `List` [0] https://jersey.java.net/ https://jersey.java.net/ [1] https://jax-rs-spec.java.net/ https://jax-rs-spec.java.net/