Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are form elements outside of a FORM tag semantic html5?

Tags:

html

forms

If I have a SELECT tag that will filter a table based on a user choice, does the SELECT tag need to be in a FORM tag (to be valid HTML5), if the resulting functionality will not work if JS disabled (i.e. we'll show the entire table or a 'more' link instead of doing a server-side filter on select of the form action/submit option (We may write the select in JS so it disappears from the markup if JS disabled.

Or do all form elements need to be in a form tag regardless of usage (and therefore a null 'action' attribute value).

I know HTML5 allows almost anything, I just couldn't find a definitive answer on W3, so thought I'd get your thoughts. Hope that makes sense. Cheers.

like image 625
Anon Avatar asked Mar 22 '11 01:03

Anon


People also ask

Is it necessary to enclose form field elements inside the form tag?

<input> without a <form> appears valid, yes (at least for html 4.01, look near the end of 17.2. 1): The elements used to create controls generally appear inside a FORM element, but may also appear outside of a FORM element declaration when they are used to build user interfaces.

Which tag defines a form element in HTML5?

The <form> tag is used to create an HTML form for user input. The <form> element can contain one or more of the following form elements: <input> <textarea> <button>

Can a form be inside another form?

"Every form must be enclosed within a FORM element. There can be several forms in a single document, but the FORM element can't be nested."


1 Answers

All the form controls can be used anywhere where phrasing content is expected, which means they can appear just about anywhere in the body of the document. If you don't need to have them submitted back to a server then there's no need for them to be associated with a form, however I've noticed that in some browsers you can't take advantage of the form validation features unless the elements can potentially be submitted.

One feature new to HTML5 is that form controls no longer need to be the direct child of a form element in order to be submitted with that form, the form attribute allows you to specify the id of the form the element should be submitted with.

like image 156
robertc Avatar answered Oct 11 '22 08:10

robertc