# Solved: xhtml Validation Error



## skyhigh007 (Jun 17, 2004)

Hi

What does it mean by "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." ?


```
<div id="subscription"><form method="post" action="checkMail.php"><input class="address" type="text" name="email" size="20" /> <input class="submit_it" type="submit"  value="" /></form>
```
Thanks


----------



## tomdkat (May 6, 2006)

Could you post a link to the validation error? Without seeing any context of the error, namely the highlighted area of HTML, I'm thinking the validator wants or expects an element of the specified type to precede the "input" tag.

What DOCTYPE are you using?

EDIT: Here is a XHTML form that validates:

```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type" />
  <title>XHTML Form</title>
</head>
<body>
<form method="post" action="submit.pl"><input
 size="20" name="address" /><br />
  <input value="submit" type="submit" /></form>
<br />
<form method="post" action="checkMail.php"><input
 class="address" name="email" size="20" type="text" />
  <input class="submit_it" value="" type="submit" /></form>
</body>
</html>
```
Peace...


----------



## skyhigh007 (Jun 17, 2004)

Here is the link Here


----------



## Eriksrocks (Aug 7, 2005)

tomdkat said:


> EDIT: Here is a XHTML form that validates:


But it doesn't validate against XHTML Scrict, the DOCTYPE being used in the page in question (although you wouldn't have known that because you posted before the link was posted). 

I didn't know this before, but it turns out that in XHTML Strict you can't put fields directly within a tag. They must be nested within one of the tags listed in the error message ("p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del"). 

So I'll demonstrate on tomdkat's example. If we were to just surround all of the input fields with a , and then surround the whole form with a :


```
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type" />
<title>XHTML Form</title>
</head>
<body>
[COLOR="Blue"][B]<div>[/B][/COLOR]
<form method="post" action="submit.pl">
[B][COLOR="Red"]<div>[/COLOR][/B]<input size="20" name="address" /><br />
<input value="submit" type="submit" />[COLOR="Red"][B]</div>[/B][/COLOR]</form>
<form method="post" action="checkMail.php">
[COLOR="Red"][B]<div>[/B][/COLOR]
<input class="address" name="email" size="20" type="text" />
<input class="submit_it" value="" type="submit" />[COLOR="Red"][B]</div>[/B][/COLOR]</form>
[COLOR="Blue"][B]</div>[/B][/COLOR]
</body>
</html>
```
It validates perfectly! 

Alternately you could use fieldsets, paragraphs, etc. as your containers instead of divs.


----------



## tomdkat (May 6, 2006)

Eriksrocks said:


> But it doesn't validate against XHTML Scrict, the DOCTYPE being used in the page in question (although you wouldn't have known that because you posted before the link was posted).


 



> I didn't know this before, but it turns out that in XHTML Strict you can't put fields directly within a tag. They must be nested within one of the tags listed in the error message ("p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "pre", "address", "fieldset", "ins", "del").


Here is the explanation from the validator:


> The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.
> 
> *One possible cause for this message is that you have attempted to put a block-level element (such as "
> 
> ...




This leads me to think the "form" element isn't a block-level element. Does anyone know what kind of element "form" is in XHTML?



> So I'll demonstrate on tomdkat's example. If we were to just surround all of the input fields with a , and then surround the whole form with a :





> It validates perfectly!
> 
> Alternately you could use fieldsets, paragraphs, etc. as your containers instead of divs.



Great work! :up:

Peace...


----------



## Eriksrocks (Aug 7, 2005)

tomdkat said:


> > *One possible cause for this message is that you have attempted to put a block-level element (such as "
> >
> > " or "
> >
> ...





I'm guessing it has to be a block-level element, otherwise you would receive validation errors when placing a inside of a (block-level inside inline element), which obviously you don't.


----------



## tomdkat (May 6, 2006)

If that's the case, then having an input element inside the form element should work since form is already a block-level element. Unless a form is neither a "block-level" or an "inline-level" element.

EDIT: I guess this is the more important part of the description:


> The mentioned element is not allowed to appear in the context in which you've placed it; *the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned*. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.


EDIT #2: Check this out. Looks like "fieldset" is a maybe a better way to define forms in XHTML?

Peace...


----------



## Eriksrocks (Aug 7, 2005)

tomdkat said:


> If that's the case, then having an input element inside the form element should work since form is already a block-level element. Unless a form is neither a "block-level" or an "inline-level" element.


Are there other element types besides block-level and inline-level? 

From the link you posted in EDIT #2 (at the very bottom):


> *Contains*
> 
> Block elements, except form, at any depth
> fieldset


That basically means to me that can contain *any block element, except another form tag, and the tag*. However, *it cannot contain any other elements that are not block elements.* Input isn't a block-level element and it isn't the fieldset tag, so thus it can't be contained directly within a tag in XHTML. 



tomdkat said:


> EDIT #2: Check this out. Looks like "fieldset" is a maybe a better way to define forms in XHTML?


I suppose technically yes because a "fieldset" is meant to contain fields so it seems like the more logical way to do it.  So you should substitute my div changes for fieldsets if you want to be technically correct.


----------



## tomdkat (May 6, 2006)

Eriksrocks said:


> Are there other element types besides block-level and inline-level?


Actually, yes there are.  On the page I linked to in EDIT #2 of my post above, it lists block elements, inline elements, list item elements, and table content elements. I wasn't aware that there were elements type other than block or inline until just now. You learn something new every day. 



> That basically means to me that can contain *any block element, except another form tag, and the tag*. However, *it cannot contain any other elements that are not block elements.* Input isn't a block-level element and it isn't the fieldset tag, so thus it can't be contained directly within a tag in XHTML.


Yep, that's how I read that as well.



> I suppose technically yes because a "fieldset" is meant to contain fields so it seems like the more logical way to do it.  So you should substitute my div changes for fieldsets if you want to be technically correct.


Well, I don't know if I would do that but "fieldsets" are new to me as well. Did this exist in HTML 4?

Peace...


----------



## Eriksrocks (Aug 7, 2005)

tomdkat said:


> Well, I don't know if I would do that but "fieldsets" are new to me as well. Did this exist in HTML 4?


I believe so, yes. I've heard of them and used them before but I just haven't used them as often. Without extra styling changes they basically just draw a box around the fields, like you see in the second example here. But you could easily use them just for nesting purposes by using CSS to remove the default styling. 

I guess you are right and I would probably use divs instead of fieldsets in an XHTML form because I'm more familiar with them. But I _think_ fieldsets are the "technically" correct way, although it won't really matter to the end user.


----------



## skyhigh007 (Jun 17, 2004)

Looks like I have to add another just for two inputs.


----------



## Eriksrocks (Aug 7, 2005)

Are you complaining?  It's not going to affect anything other then you're page validating correctly.


----------



## skyhigh007 (Jun 17, 2004)

I'm not complaining at all. I'm glad you guys helped me out.


----------



## Eriksrocks (Aug 7, 2005)

skyhigh007 said:


> I'm not complaining at all. I'm glad you guys helped me out.


Ok, just checking.


----------

