When I submit a form with a duplicate name, does it send all the forms with the same name?

There are a lot of form tags with the same name on the same page, when I click submit on one of them what is the expected behavior?

Upvotes: 0

Views: 1196

Answers (4)

rocksfrow
rocksfrow

Reputation: 970

If you have multiple forms with the same name it won't make a difference, only the form which contains the submit button that was pressed will be submitted. The form name is not actually referenced in the GET or POST request the FORM makes after being submitted.

If you are submitting the FORM via javascript the behavior may vary. Even then having duplicate names won't make a difference as long as you reference the forms by unique IDs. In the event of attempting to reference multiple forms by the matching FORM names and submitting them via javascript you would most likely get a javascript error or the first/last form of the set would be submitted depending on the browsers behavior.

Upvotes: 6

mario
mario

Reputation: 145482

The name= attribute has no special meaning in regards to which form data is going to be submitted. (And it's going to be the form the submit button associates to.)

http://www.w3.org/TR/html4/interact/forms.html#h-17.3

It's sort of equivalent to the id= attribute, so avoiding identical names would be a good idea regardless.

Upvotes: 0

comu
comu

Reputation: 921

If you are using JavaScript/jQuery to submit the forms, than it will only submit the 1st instance of the form. If you are using a submit button for each individual form, it should only submit that form, however some browsers may do this different, although I doubt it.

However...

Why would you ever have multiple forms with the Same name anyway? I only see that as making it harder for your self to trouble shoot. Just name them seperately. Eg...

<form name="form0"></form>
<form name="form1"></form>
<form name="form2"></form>

Upvotes: 1

Vikk
Vikk

Reputation: 3363

The form which contains that submit button will be submitted.

Upvotes: 2

Related Questions