Basically, can I have input names like <input name="total sum(userID2223)" type="text" />
and similar? Are there any rules for that?

- 7,761
- 16
- 33
- 49

- 21,085
- 65
- 193
- 298
-
This is the answer for you: http://stackoverflow.com/a/13858670/362536 – Brad Jul 01 '13 at 00:20
-
1Why would you want to? The names relate to the fields as they appear in the document. In your example I'd use `totalsum` or something similar. If you start naming them in some way that relates them to a specific user on your system your back-end processing will become a nightmare. If you need to include user-specific data do it in a `hidden` field. – Jul 01 '13 at 00:21
2 Answers
Yes you can. When PHP reads the form, you will be able to address the data with $POST["total sum(userID2223)"]
.
Without knowing more about what you are trying to do I can't say for sure, but there's probably a bad design decision happening somewhere.

- 11,007
- 4
- 31
- 50
It's not allowed in HTML4: From http://www.w3.org/TR/html401/types.html#type-cdata
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Interestingly, it has long been common to use []
in NAME
attributes, even though not allowed by the above; PHP will turn these inputs into arrays in _$GET
and $_POST
.
It's allowed in HTML5: From http://www.w3.org/TR/html5/forms.html#attr-fe-name
Any non-empty value for name is allowed, but the names "charset" and "isindex" are special
For your application, I would recommend array notation:
<input name="total[2223]" type="text" />
Then in PHP it would be $_POST['total'][2223]
.

- 741,623
- 53
- 500
- 612
-
1The `name` attribute in HTML 4 is defined as containing CDATA, not a NAME token. – Quentin Feb 05 '14 at 16:02