Can you nest html forms?
In a word, no. You can have several forms in a page but they should not be nested.
From the html5 working draft:
4.10.3 The
form
elementContent model:
Flow content, but with no form element descendants.
I ran into a similar problem, and I know that is not an answer to the question, but it can be of help to someone with this kind of problem:
if there is need to put the elements of two or more forms in a given sequence, the HTML5 <input> form
attribute can be the solution.
From http://www.w3schools.com/tags/att_input_form.asp:
- The form attribute is new in HTML5.
- Specifies which
<form>
element an<input>
element belongs to. The value of this attribute must be the id attribute of a<form>
element in the same document.
Scenario:
- input_Form1_n1
- input_Form2_n1
- input_Form1_n2
- input_Form2_n2
Implementation:
<form id="Form1" action="Action1.php" method="post"></form>
<form id="Form2" action="Action2.php" method="post"></form>
<input type="text" name="input_Form1_n1" form="Form1" />
<input type="text" name="input_Form2_n1" form="Form2" />
<input type="text" name="input_Form1_n2" form="Form1" />
<input type="text" name="input_Form2_n2" form="Form2" />
<input type="submit" name="button1" value="buttonVal1" form="Form1" />
<input type="submit" name="button2" value="buttonVal2" form="Form2" />
Here you'll find browser's compatibility.
The second form will be ignored, see the snippet from WebKit for example:
bool HTMLParser::formCreateErrorCheck(Token* t, RefPtr<Node>& result)
{
// Only create a new form if we're not already inside one.
// This is consistent with other browsers' behavior.
if (!m_currentFormElement) {
m_currentFormElement = new HTMLFormElement(formTag, m_document);
result = m_currentFormElement;
pCloserCreateErrorCheck(t, result);
}
return false;
}