Giovanni Lovato
Giovanni Lovato

Reputation: 2273

HTML standards for input names on complex forms

There is a standard or a good practice on choosing the name attribute value in complex HTML form input elements? For example:

<input type="text" name="post[comments][0][author][name]" />

But what about multiple values? Should I use

<input type="file" multiple name="post[attachments]" />

or

<input type="file" multiple name="post[attachments][]" />

?

PHP supports only the latter, but W3C uses the former in their examples. Since I'm parsing raw multipart/form-data entities, I don't rely on a specific language; I'm looking for standards, best practices or suggestions.

Upvotes: 10

Views: 3193

Answers (2)

unor
unor

Reputation: 96547

The HTML5 spec doesn’t define any format or best practices for the content of the name attribute. It only reserves the two values isindex and _charset_.

(UPDATE: HTML5 defines field name keywords for the autocomplete attribute.)

For e-commerce forms, there is RFC 3106: ECML v1.1: Field Specifications for E-Commerce. It defines several keywords that can be used as name values for the input element (according to section 2.2).

In http://wiki.whatwg.org/wiki/Autocomplete_Types it is explained why this is not a good way to achieve autocomplete functionality:

RFC 3106 requires websites to conform to a set of input naming standards, effectively co-opting the name attribute — which has other, sometimes conflicting, uses.

Upvotes: 2

Quentin
Quentin

Reputation: 943193

There is a standard or a good practice on choosing the name attribute value in complex HTML form input elements?

There are no standards for this.

The syntax you use it particular to PHP's form data parsing engine (there are a couple of modules for other languages that emulate it).

It's a convenient syntax when dealing with complex data structures in forms.

Upvotes: 1

Related Questions