Forum Moderators: open

Message Too Old, No Replies

Why does forms require additional structure?

And since when were buttons considered paragraphs?

         

Wertigon

1:20 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Hey all. This is something I've been wondering about for some time now... And that is why forms somehow seem to require additional structure beyond the form tag?

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?

pixel_juice

10:16 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Have a look at this thread:
HTML Form Validation Problem [webmasterworld.com]

andreasfriedrich spells it out pretty well in msg #6 & 8 :)

Purple Martin

12:07 am on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Forms don't require additional structure if you use the complete set of form tags. In other words, use a fieldset!

<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.

Wertigon

2:12 pm on Mar 25, 2004 (gmt 0)

10+ Year Member



Okay... I think I understand.

So a form basicly consists of fields that contain input elements in them, right?

If so then I get it. Thanks for the help. :)

Purple Martin

10:20 pm on Mar 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Almost, but not quite.

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.