Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 206
Giovanni Lovato Avatar asked May 22 '13 14:05

Giovanni Lovato


1 Answers

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.

like image 151
unor Avatar answered Oct 12 '22 01:10

unor