Search code examples
htmlweb-standards

How are same named input tags represented on the server side


While looking at some source code for different forms I ran across this piece of code

<input class="" id="Delivery_HasShippingAddress" name="Delivery.HasShippingAddress" tabindex="11" type="checkbox" value="true" />
<input name="Delivery.HasShippingAddress" type="hidden" value="false" />

which belongs to the same form. As you can see there are two input tags with the same name though different type and id. If the form is submitted tamper data lists them "both" as POSTDATA:

Delivery.HasShippingAddress=true
Delivery.HasShippingAddress=false

I am now wondering how this request would be processed?

Does the Server override the first value with the second or does the first value received dominate or are maybe both values listed (would be weird though)?


Solution

  • The browser will encode the data as a string. Typically:

    Delivery.HasShippingAddress=true&Delivery.HasShippingAddress=false
    

    What happens on the server depends on your form processing library. Usually it will decode according to this spec. Then it will present the data to the programmer.

    Some will present an array of values. Some will present just one of the values. Some might do either depending on the function you call.