Search code examples
htmlvalidationforms

Is it valid to have two input elements with the same name?


i.e.:

<form 1>
<input type="hidden" name="url" value="1">
</form 1>

and

<form 2>
<input type="hidden" name="url" value="2">
</form 2>

Is this allowed and valid?


Solution

  • Yes, it is valid

    This is Good

    <form name="form1">
      <input type="hidden" name="url" value="1">
    </form>
    
    <form name="form2">
      <input type="hidden" name="url" value="2">
    </form>
    

    This is also fine and will generally be interpreted as an array of values, e.g. {url: [1, 2]}, depending on what your server does. In a URL encoding, it will look like url=1&url=2.

    <form name="form1">
      <input type="hidden" name="url" value="1">
      <input type="hidden" name="url" value="2">
    </form>