Input field name starts with a number

爱⌒轻易说出口 提交于 2019-12-03 08:42:58

问题


I have an input field whose name is an MD5 string e.g.:

<input type="hidden" name="7815696ecbf1c96e6894b779456d330e" value="1">

Now I understand that having a number as the first letter in an input field name is generally bad practice, but are there any side-effects to this such as a certain browser won't send it in the POST request?


回答1:


An ID attribute would have had to begin with a letter as per the HTML 4.01 W3C specification, however since the NAME attribute of input elements is of CDATA type (Source), this restriction does not apply.

One real restriction you get on NAME attributes is when you submit a form with the GET method, because in this case, form data must be restricted to ASCII codes (Source).




回答2:


The HTML spec doesn't restrict the control name in any way. In fact it even says that the control name is URL-encoded and that spaces and non-alphanumeric characters are handled in a certain way, so obviously the designers anticipated names having an arbitrary format.




回答3:


As far as I know, you should have no problem in any browser.
But you can always consider to prepend some kind of string, also for convenience:

e.g.,

<input type="hidden" name="h.7815696ecbf1c96e6894b779456d330e" value="1">

Which can help someway.



来源:https://stackoverflow.com/questions/2469355/input-field-name-starts-with-a-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!