Forum Moderators: open
What I mean is that if I have a form, neatly styled, like this (Doctype is HTML 4.01 Strict):
<form method="POST" action="php/login.php">
<input type="hidden" name="sitename" value="site1">
<label>Login name<input type="text" name="login"></label>
<label>Password<input type="text" name="login"></label>
<input type="submit" name="submit" value="Login">
<input type="reset" name="reset" value="Reset">
</form> The validator throws out error after error, saying that I need a paragraph or div or something. Yet, if I do it like this:
<form method="POST" action="php/login.php">
<div>
<input type="hidden" name="sitename" value="site1">
<label>Login name<input type="text" name="login"></label>
<label>Password<input type="text" name="login"></label>
<input type="submit" name="submit" value="Login">
<input type="reset" name="reset" value="Reset">
</div>
</form> The code all of a sudden validates. Why is this so? I did not add any extra structure to the code, just a div element. One would think that the form already has enough structure; but clearly it is not so.
I fail to see why an input box, especially a hidden input box, should have to be counted as a paragraph, let alone a header or address. Is it only something the HTML 4.01 WG happened to forget to "fix", or am I missing something here?
andreasfriedrich spells it out pretty well in msg #6 & 8 :)
<form>
<fieldset>
<legend>Please enter your login details</legend>
<input type="hidden" name="sitename" value="site1">
<label>Login name<input type="text" name="login"></label>
<label>Password<input type="text" name="login"></label>
<input type="submit" name="submit" value="Login">
<input type="reset" name="reset" value="Reset">
</fieldset>
</form>
The legend is optional (I included it here to remind people of it's existance, as in my opinion it's underused).
If you don't like the default look of the fieldset you can change it with CSS.
A form should consist of fieldsets ( = groups of fields) that contain fields ( = input elements) in them.
People often don't bother with fieldsets (particularly if their form only has one group of fields), however that can lead to the validation problem that you've already discovered.