Does HTML5 require an action attribute for forms? [duplicate]

五迷三道 提交于 2019-12-18 07:43:20

问题


I've just run a webpage of mine through the W3C HTML5 validator, and it validates completely, even though the form in it doesn't have an action attribute, which the HTML 4 validator always complains about. Considering the fact that the HTML5 validator is still experimental, is the fact that the form validating despite not having an action attribute a problem with the validator, or has the HTML5 spec changed to not require that attribute any more?


回答1:


According to the specification action is not mandatory:

The action and formaction content attributes, if specified, must have a value that is a valid non-empty URL potentially surrounded by spaces.

Although, section 4.10.1.3 Configuring a form to communicate with a server states that:

You also have to specify the URL of the service that will handle the submitted data, using the action attribute.

So, the specification says that if you want your form to communicate with a server it shall provide the action attribute. Which, in my opinion, is not the only truth as you can specify actions on buttons as well.

EDIT: I must admit that I can't finally answer your question with Yes or No...



来源:https://stackoverflow.com/questions/7048833/does-html5-require-an-action-attribute-for-forms

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