Why this give error in W3c html validation ? I’m using HTML 4.01 Strict doctype.
<form method="get" action="/search" id="search">
<input type="text" value="search" maxlength="80" class="textbox" >
</form>
and this does not?
<form method="get" action="/search" id="search">
<div>
<input type="text" value="search" maxlength="80" class="textbox" >
</div>
</form>
This is error
document type does not allow element
“INPUT” here; missing one of “P”,
“H1”, “H2”, “H3”, “H4”, “H5”, “H6”,
“PRE”, “DIV”, “ADDRESS” start-tag
Is it necessary to put input in a div?
The official reason is that in HTML4 strict the FORM elements can only contain block elements, but block elements are in turn allowed to contain form inputs. Hence, the structure
form->block element->form inputis what has to be used.I cannot find a serious reason, WHY it is so. It sounds like the authors of HTML did not want to allow forms that start on one line, then wrap over to next line and then have a submit button somewhere on the third line (which you can still achieve, by redefining the
displayproperty of a form, if you need. For instance, this article on 24ways just states that “it is a difference between Transitional and Strict standards”.Another comparison states (they are talking about xhtml vs html, but the idea is the same):
This makes me think that FORM element is not “semantic enough” to contain other elements. It is not normally meant to be used for marking up your code, it is more like a technical element which shows where to post the data to. Hence, it technically is a BLOCK element, but it needs something more “semantic” to contain the actual input fields.