Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Forms With Input Fields With The Same Name Attribute? Good Or Bad?

Is it an acceptable practice to have multiple HTML forms on a page with input fields that share the same name attribute? For example, the page contains a listing of all players and users are allowed to vote for the best player so next to each player card there is this form:

<form class="vote-for-player" enctype="application/x-www-form-urlencoded" method="post" action="/index/vote-for-best-player">
    <input type="hidden" name="player_id" value="1" />
    <input type="submit" name="vote_for_player" value="Vote" class="input-submit" />
</form>

Value attribute of the hidden input field is different for each form, of course.

Let's say there are 20 forms like this on the page so that means 20 input fields with the name equal to "player_id". If I pass that page through HTML validator, it is valid even with the XHTML 1.0 Strict doctype. But is this an acceptable practice from web standards or accessibility perspective?

One thing I know for sure, it makes the server side processing of the page easier as I just need to load value from one POST field called player_id.

like image 692
Richard Knop Avatar asked Sep 07 '25 18:09

Richard Knop


1 Answers

Agree with above answer. Name is totally ok, and will be passed as response parameter of your form. Different story would be if your input elements would have same id's as well - some browsers might have problems traversing dom of your document.

Again, think of bunch of radio buttons, where users can select gender etc. They must have same name (but different id's)...

like image 103
Greg Avatar answered Sep 10 '25 10:09

Greg