HTML standards for input names on complex forms
Asked Answered
Z

2

10

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.

Zetes answered 22/5, 2013 at 14:51 Comment(1)
Didn't knew we can do something like thisMargheritamargi
B
2

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.

Backed answered 24/5, 2013 at 13:44 Comment(0)
M
1

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.

Marysa answered 22/5, 2013 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.