Alex Erwin
Alex Erwin

Reputation: 343

Is there an HTML 5 way of submitting fields with the same name but different identifiers?

I would like to submit multiple ROWS of field columns using an HTML form with the only difference being the corresponding server side identifier.

Pseudo:

    ID(257) -> Name, Color, Price
    ID(415) -> Name, Color, Price

I prefer NOT to:

  1. Have each group as its own form and submit via JavaScript.
  2. Concatenate the id and real name and unmerge on the server.

Thanks

Upvotes: 0

Views: 49

Answers (2)

chrki
chrki

Reputation: 6323

You can use the same input name when attaching a [] to it, in PHP this will result in an array on submission:

<?php
print_r($_POST);
?>

<form method="post">
<input type="text" name="name[257]">
<input type="text" name="name[415]">
<input type="submit">
</form>

Result:

Array
(
    [name] => Array
        (
            [257] => first field
            [415] => second field
        )

)

Upvotes: 1

John Conde
John Conde

Reputation: 219804

If you're using PHP as your server side language this is easy. Just name your fields with brackets which is array syntax in PHP:

Pseudo code:

name[1] = 'Name, Color, Price'
name[2] = 'Name, Color, Price'

Upvotes: 0

Related Questions