Names of HTML form naming conventions
Asked Answered
A

3

8

In Rails and CakePHP1.2, forms tend to include input elements with names like the following:

<input name="comment[author]" />

Is there a formal name for the notation used in the "name" attribute?

Likewise, in CakePHP1.1 I do believe that the same would have looked like this:

<input name="comment/author" />

Again, is there a formal name for the notation used in the "name" attribute?

Archilochus answered 26/1, 2010 at 20:59 Comment(2)
I don't think it originally had a name when it originated in PHP. It was just seen as duplicating the in-language array dereference format a[b]. Since then the PHP array dereference has been made to require quotes (a['b']) because it's so horribly ambiguous otherwise, but the name format hasn't been updated to match. Some other environments have adopted PHP's syntax, but there are just as many that have gone for alternatives (eg. a.b).Odo
I call it "namespace", as it will form the request->data array with specific keys. It is, in this case, a framework specific thing for CakePHP to do it this way. So there is no point in comparing it to others, or making this a generic question of some sort IMO.Occur
E
1

in cake php, the naming scheme is in multidimensional array access format, though i'm not really sure what you'd call that. multidimensional array keying?

official php docs call it "square bracket notation"

Basically, I'm not sure that cakephp has a specific name for this... This is because it is simply 'bracket notation' for keyed array access.

Here's an example from the cakephp docs. It illustrates naming elements with bracket notation in cakephp, and how this is used to pre-populate values.

using cake php FormHelper we create a hidden id field:

echo $this->Form->hidden('id'):

this outputs the following:

<!-- data comes from $this->request->data -->
<input name="data[User][id]" id="UserId" type="hidden" />

Assuming that the value held by data[User][id] is 10, the input with an ID of UserId will have a value of 10.

Endometrium answered 27/3, 2013 at 3:36 Comment(1)
If you can provide a citation the green tick is yours.Archilochus
B
4

In Rails, this is referred to as the forms microformat (at least by some). Lots of different frameworks seem to be standardizing on that first format. I'd imagine CakePHP has updated their libraries to conform to that standard. There's an obsessively in-depth explanation available that's only somewhat Rails-specific. The original microformat apparently comes from PHP.

Borders answered 26/1, 2010 at 21:49 Comment(0)
E
1

in cake php, the naming scheme is in multidimensional array access format, though i'm not really sure what you'd call that. multidimensional array keying?

official php docs call it "square bracket notation"

Basically, I'm not sure that cakephp has a specific name for this... This is because it is simply 'bracket notation' for keyed array access.

Here's an example from the cakephp docs. It illustrates naming elements with bracket notation in cakephp, and how this is used to pre-populate values.

using cake php FormHelper we create a hidden id field:

echo $this->Form->hidden('id'):

this outputs the following:

<!-- data comes from $this->request->data -->
<input name="data[User][id]" id="UserId" type="hidden" />

Assuming that the value held by data[User][id] is 10, the input with an ID of UserId will have a value of 10.

Endometrium answered 27/3, 2013 at 3:36 Comment(1)
If you can provide a citation the green tick is yours.Archilochus
D
0

In Rails, the string value assigned to the name attribute in a form element is passed to a Controller as a hash inside the params[] hash, indexed by key.

<input name="username"/>

Will show up in the controller as params[:username].

<input name="user[name]"/>

Will show up in the controller as params[:user][:name].

And so on. If you want to read more about how to generate these and what to expect, consult the ActionView and ActionController documentation.

Here is a link to the ActionController overview, which is a great guide.

Diphenylamine answered 5/3, 2013 at 23:9 Comment(1)
My question isn't about how the names are interpreted, it's about the term used to describe this naming convention or format.Archilochus

© 2022 - 2024 — McMap. All rights reserved.