w3c validator gives 'document type does not allow element “input” here…' error

拜拜、爱过 提交于 2019-12-19 00:19:05

问题


I got this error when validating my page with w3c's validator.

Source:

<form action="form.php" method="post">
<input type="text"/>
</form>

Can someone show me why I may have gotten this error? Thanks in advance!


回答1:


This answer applies to XHTML, not HTML5.

The form and body element only accept block level children <form action="/"> <input type="submit"> </form> … will produce the error:

document type does not allow element "input" here; missing one of "p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del" start-tag.

In Strict variants of (X)HTML, a form element may have only block elements as its children, but form controls (such as input elements) are inline elements. The solution is to pick a block element with appropriate semantics that may contain inline elements; helpfully the validator produces a list that can help you narrow it down.

When it comes to a form, appropriate elements are usually fieldset or a plain div.

Source - Dorward Online

So doing something like

<form action="form.php" method="post">
    <fieldset>
        <input type="text"/>
    </fieldset>
</form>

will solve your problem.



来源:https://stackoverflow.com/questions/5865963/w3c-validator-gives-document-type-does-not-allow-element-input-here-error

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