In my existing web page layout, which involves multiple files, one specifying the high-level layout, there are two elements, one for a left column, and one for a right colu
(Sorry to unaccept an answer and post my own, but I just found out apparently the answers I got are not up to date with HTML5!)
HTML5 introduces a form=
attribute for <input>
element [1]. So that you can do <input form="form1" name="input1" /> and have it in a nested inner form, or even outside of the
` element.
[1] http://www.w3.org/TR/html5/association-of-controls-and-forms.html#attr-fae-form
Short answer is No, you cannot have two separate form
tags acting as a 1 form, instead wrap the whole thing inside a wrapping div tag
<form>
<!-- some content with input elements has no relation with other form tag on this page, it just ends where you specify the end tag -->
</form>
<form>
<!-- Has no relation with the first form -->
</form>
The only way to submit both forms is to wrap both <div>
s within a single <form>
tag. Or, you can use jQuery/JavaScript to aggregate the data and submit them together as one submission.
I think people are missing the question. A <form>
can contain whatever elements it needs. If the layout of your page is something like:
<body>
<div id="leftColumn"><input name="foo" type="text"></div>
<div id="rightColumn"><input name="bar" type="text"></div>
<body>
You don't need separate foo
and bar
forms. You can happily encase both of those <div>
s inside a single <form>
element:
<body>
<form name="onlyOneForm">
<div id="leftColumn"><input name="foo" type="text"></div>
<div id="rightColumn"><input name="bar" type="text"></div>
</form>
<body>