View Full Version : nomadic form elements

Oct 30th, 2004, 05:57 AM
Is there any reason to enclose inputs and select elements, which are used for the document GUI, in a form element?

They validate either way.

Oct 30th, 2004, 09:39 AM
I'll take that as a no.

Good to go.

Oct 30th, 2004, 10:04 AM
As for the other way around:

Should a form element be avoided in a situation where no processing of submitted data is needed (though form controls are present)?

I'll assume yes.

Puffin the Erb
Oct 30th, 2004, 03:12 PM
You'll be okay in newer browsers to omit the <form> tag when using form elements.
Using the <form> tag without attributes won't validate but is needed by some older browsers in order for form elements to work.
For example, the <button> tag will not work in browsers based on html 3.2 so you need the <input type="button"> line. However, to be sure this works, you need the <form> tag, but then the code won't validate if you omit <form> attributes.
It's a wonderful case of theory versus real world and will very much depend on your target audience.

Oct 30th, 2004, 03:23 PM
Good point; thank you.

Oct 30th, 2004, 07:27 PM
No this is wrong ...

A form must have a <form> tag, otherwise it isn't a form. The only mandatory attribute is "action", but you can set that to an empty string if you're not submitting it.

You can't ommit the form tag, and you don't need to worry about HTML 3.2 compatibility.

Puffin the Erb
Oct 30th, 2004, 09:03 PM
Hi there.
He doesn't need a form just the effects of certain form elements. These elements will not work in older user agents ( ie Netscape 4 )without the <form> tag.
In my opinion, you should worry about html 3.2 friendly browsers for accessibility reasons - for instance text-only browsers support more html 3.2 than 4x, with CSS being unsupported. The user applies styling to the tags from a client-side file.
Anyway, my point was that making the code valid would stop it working in some older browsers but that this may not be a concern when considering his target audience.

Oct 31st, 2004, 03:52 AM
You can't ommit the form tag
I don't understand.

Form controls not contained in a <form> validate as 4.01-strict. Apart from backwards compat, why should "form" be used when nothing is to be submitted?

Nov 9th, 2004, 03:53 AM
For the sake of semantics - a form element should be inside a form, because it's a form element. There's no reason why the form element needs to have visual impact, it just ought to be there for semantics.

Nov 9th, 2004, 07:14 AM
If it's not being used as a part of a form, why are you using it at all? Using form elements for things like navigation is a poor practice and worth avoiding. :)