tags:

views:

41

answers:

2

I just ran this simple code through the w3c validation service (http://validator.w3.org/check). Here is the code I'm running through:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"
    >
<html lang="en">
<head>
    <title><!-- Insert your title here --></title>
</head>
<body>
<form name="testform" action="/" method="post">
    <input type="text" name="testfield">
</form>
</body>
</html>

I'm getting the following error on the input field:

Line 10, Column 40: document type does not allow element "INPUT" here; missing one of "P", "H1", "H2", "H3", "H4", "H5", "H6", "PRE", "DIV", "ADDRESS" start-tag

I don't see anything wrong with it. Any ideas?

+6  A: 

The problems is with how the FORM element is define in the DTD:

<!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

So, it can either have a %block (except for FORM) or SCRIPT element.

And %block is defined as:

<!ENTITY % block
 "P | %heading; | %list; | %preformatted; | DL | DIV | NOSCRIPT |
  BLOCKQUOTE | FORM | HR | TABLE | FIELDSET | ADDRESS">

And the rest:

<!ENTITY % heading "H1|H2|H3|H4|H5|H6">

<!ENTITY % list "UL | OL">

<!ENTITY % preformatted "PRE">

Since your form does not contain any of these as a direct child, the page failed validation.

Oded
Thanks for the response. I'm not quite sure what that all means though. What would I have to change in my code to correct the problem?
blcArmadillo
@blcArmadillo - the [DTD](http://www.w3.org/TR/html4/strict.dtd) is the definition of HTML 4.01 Strict and that's what it validates against. In short, one of the elements (tags) above should be immediately after the `<form>` tag. Since `<input>` is not in the list, it is not valid immediately inside the `<form>` tag.
Oded
It's worth adding that there's another rule beyond this. The above production only says that you can't have a form immediately inside a form (`<form><form>...</form></form>`). In fact, you can't have a form anywhere inside a form, but that can't be expressed in a DTD (likewise, you can't have an `<a>` anywhere inside an `<a>`).
Jon Hanna
+1  A: 

Played around with it a bit--put a "div" tag around the "input" tag:

<div>
    <input type="text" name="testfield">
</div>
Russ