5

Why does the WHATWG disallow nested forms in HTML 4 and HTML5?

EDIT: Problem is originally described at How do you overcome the HTML form nesting limitation?

In short author says: You are making a blog app and you have a form with some fields for creating a new post and a toolbar with "actions" like "Save", "Delete", "Cancel"... The only problem is that pressing "Delete", will submit ALL the form fields on the server even though the only thing needed for this action is a Hidden input with the post-id.

So, it is a question about an elegant solution (without JavaScript) for several buttons in a form to submit different sets of input fields (like several forms could allow) and to line up UI into single entity ("form") from user perspective.

Comment from that discussion: it's almost impossible to completely separate the elements' screen position from their position in the document.

EDIT: I found interesting note https://web.archive.org/web/20170420110433/http://anderwald.info/internet/nesting-form-tags-in-xhtml/ - that (X)HTML disallows nesting forms like "form > form", but allows "form > fieldset > form", W3 validator says it is valid, but browsers have bugs with such nesting.

Dave Miller
  • 536
  • 3
  • 19
Nishi
  • 10,634
  • 3
  • 27
  • 36
  • 7
    You can't blame the WHATWG for HTML4, it didn't even exist when HTML4 was written. – Ms2ger May 13 '10 at 20:21
  • 2
    In your blog app example, I would personally just create two
    elements, basically give your Delete button it's own
    . I honestly can't see a need for nesting forms when HTML4/5 allows multiple forms anyway.
    – Sunday Ironfoot May 19 '10 at 15:36

2 Answers2

2

As far as HTML5 (the draft spec) goes, the situation is not nearly as clear cut as David Dorward suggests. What is true, is that there's no way that nested forms can be specified in the text/html serialization in a backward-compatible way without adding a new way of delimiting forms in markup.

On the other hand, in the application/xhtml+xml serialization, it's not only possible to markup nested forms, but HTML5 goes to some lengths ( http://dev.w3.org/html5/spec/forms.html#form-owner ) to specify what should happen in this case. Further, a quick test around the latest versions of FireFox, Opera, Chrome, and Safari, plus IE9 platform preview shows that they all do what HTML5 specifies.

So, it could have been valid in the HTML5 content model, but it isn't. What determines what is valid and what isn't rests largely on use-cases. So far, no one has provided a sufficiently compelling use case to WHATWG or the W3C HTML WG for making nested forms a part of valid HTML5.

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • 1
    I edited the question and added a link to the use case... How do you think, is it a sufficiently compelling use case? – Nishi May 13 '10 at 21:15
  • Form attribute (form owner) from HTML5 seems to solve the case, it is cool, thanks! – Nishi May 13 '10 at 21:31
-3

WHATWG doesn't disallow nested forms in HTML 4 — they have nothing to do with the language, and they don't have as much to do with HTML 5 as you seem to think.

Nested forms are not allowed because they wouldn't make sense, and if you specified something vaguely sane, it wouldn't be backwards compatible with current browsers.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 2
    But http://stackoverflow.com/questions/597596/how-do-you-overcome-the-html-form-nesting-limitation does make sense for me. – Nishi May 13 '10 at 19:08
  • 1
    WHATWG doesn't have much to do with HTML5? Wow, that is so wrong. Try this @Quentin: Go to the HTML spec on the WHATWG. Submit a comment. Know where it goes? The W3C's site, as a bug, that gets resolved by the W3C editors. No wonder you've been marked down. These groups are working together on HTML5. – james.garriss Jul 22 '11 at 19:20
  • @james.garriss — I said "as must as you seem to think" not "much at all". They contribute, they don't make the final decision by themselves. – Quentin Jul 22 '11 at 23:12