Click to See Complete Forum and Search --> : XHTML Validation and Forms


aj_nsc
02-25-2007, 02:36 PM
Anybody want to tell me why this would be invalid XHTML 1.0 strict? (If it's not, then I would like to point out then there's a problem with W3C's XHTML Validator - trust me, I checked - I correctly checked, I'm not a beginner).

In order for the below code to validate the form tag has to have a nested block level element, (before any content, obviously). I was unaware of this. Can anyone point me to the rules of using forms with XHTML?

For space sake, pretend I have the doctype and all that jazz declared


...
<body>
<div>
<form method="post" action="script.php">
<input type="text" name="something" size="25" />
</form>
</div>
</body>
...

Mr Initial Man
02-25-2007, 10:08 PM
You have to have <input> elements in a block-level element that is WITHIN <form>

Behold:
<body>
<div>
<form method="post" action="script.php">
<div><input type="text" name="something" size="25" /></div>
</form>
</div>
</body>


If you want to have multiple inputs, use a list:

<body>
<div>
<form method="post" action="script.php">
<ul>
<li><input type="text" name="something" size="25" /></li>
<li><input type="text" name="something2" size="25" /></li>
</ul>
</form>
</div>
</body>

ray326
02-25-2007, 11:46 PM
The inner block container is required for HTML 4.01 Strict, too.
http://www.w3.org/TR/html401/interact/forms.html#edef-FORM

A "natural" block element to use would be fieldset.
http://www.w3.org/TR/html401/interact/forms.html#edef-FIELDSET
<form ...>
<fieldset><legend>...</legend>
<input .../>
</fieldset>
</form>

Mr Initial Man
02-26-2007, 12:06 AM
Oh, yes. Fieldset does work, doesn't it?