Forum Moderators: open

Message Too Old, No Replies

Putting a form inside a div gives me a validation error - why?

W3 Validation XHTML strict

         

user9

7:14 am on Oct 1, 2004 (gmt 0)

10+ Year Member



Why does the W3 Validator for XHTML strict show errors if a form is nested in a div?


<div id="header">
<form id="search" method="post" action="search.php">
<input id="term" type="text" />
<input type="submit" value="Search" />
</form>
</div>

The markup validator in Dreamweaver doesn't show any errors. More precisely, why is it not good, or why is it wrong to have a nested form within a div?

The only way around it, as far as I know, is to place the opening tag for form before the first div. However, this method looks overly complicated to me.


<form id="search" method="post" action="search.php">
<div id="header">
<input id="term" type="text" />
<input type="submit" value="Search" />
</div>
</form>

Thanks for any help

user9

10:34 am on Oct 1, 2004 (gmt 0)

10+ Year Member



It seems that someone else was having the same problems at another site.

[pmachine.com...]

Forms can be wrapped in <fieldset> </fieldset> tags, and in this manner the page will validate.

victor

10:47 am on Oct 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm fairly certain this never used to be the case until they upgraded their parser a month or two back.

CSE HTML validator also does not see this as an error.

Could it be a typo in the DTD they are using, or a parsing bug?

user9

2:20 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Hi victor

Thanks for the reply. I usually code in XHTML transitional, that's why I never ran into this problem.

However, I'm not so sure if it's really a bug. It seems that several designers either use fieldset or paragraph tags to enclose input types.

The paragraph method I found on serveral sites listed at www.stylegala.com. They are quite strict about standards in general.

I'll see if I can find out more about it.

Saltminer

4:47 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



You can put the form in a division, that's not the problem. What the validator didn't like was the input.

You can use
<div id="header">
<form id="search" method="post" action="search.php">
<p><input type="submit" value="Search" />
<input id="term" type="text" /></p>
</form>
</div>

drbrain

5:23 pm on Oct 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The form element in HTML4 is defined like this:

<!ELEMENT FORM - - (%block;¦SCRIPT)+ -(FORM)>

[w3.org...]

The (%block;¦SCRIPT) means a form can contain a block element or a script element as its children. &formctrl; elements (INPUT ¦ SELECT ¦ TEXTAREA ¦ LABEL ¦ BUTTON) are inline, so you need a table, fieldset/legend, div or similar between the form and the form elements.

Not a bug in the validator/parser/spec.

user9

6:46 pm on Oct 1, 2004 (gmt 0)

10+ Year Member



Thanks for the replies everyone. I'll be using the proper syntax for input fields from now on.

kaled

8:49 am on Oct 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The markup validator in Dreamweaver doesn't show any errors.

I've just started using DW. I very quickly discovered that whilst it's built-in validation is useful, it is very buggy.

I'm using HTML 4.01 Trans. Standard DW framesets do not validate. It doesn't detect missing ALT attributes or unencoded '&' chars is urls, and it flags a missing HREF in a <BASE> tag as an error. It also dislikes 0 as a value for <IFRAME> margins (bizarrely, it is correct here but W3C is ok with 0). There are other bugs too - like when converting tags to lower case, it changes all attribute values, including urls, events, values, etc. thereby breaking code and/or changing the rendered page.

DW is a great program, but it is buggy. For instance, when editing a templated page, if you leave off a closing attribute quote you've got problems.

The built-in validator in DW is useful, but not definitive.

Kaled.

Khemikal

2:22 pm on Oct 3, 2004 (gmt 0)

10+ Year Member



If you are using strict xhtml and you want your forms to validate put them in a fieldset.

CSS
.fieldset {margin: 0; padding: 0; border: none;}

XHTML
<fieldset class="fieldset">
</fieldset>

So...uhh...what everyone else said :)

Khem

[edited by: Khemikal at 2:25 pm (utc) on Oct. 3, 2004]