是否可以将html表单元素包装在多个表单标签中?

时间:2012-02-24 15:25:26

标签: html forms html-table tablelayout

将表单的每个元素都包含在HTML页面中的<form>标记中会不会错?我很好奇为什么会出错:

基本上我必须介绍两种形式(form1form2)并且有一些元素与第一种形式相关联而其他元素与第二种形式相关。布局必须完全基于表格并且因为元素两种形式都在页面上这里是我写的(根据http://validator.w3.org/check,代码是有效的):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
 <html>
<head>
   <title>Title of the document</title>
 </head>

 <body>
<table border="1">
    <tr>
        <td>
            <form name="form1" method="POST" action="via.php">
            Enter the first form text here!:    <input type="text" name="first"/>
            </form>
        </td>
        <td rowspan="2">
            <form name="form2" method="POST" action="via.php">
                Enter the second form text here!:<input type="text" name="second"/>
            </form>

            <form name="form1" method="POST" action="via.php">
            Enter the first form text here!:<input type="text" name="first"/>
            </form>
        </td>
  </tr>
  <tr>
        <td>
        <form name="form1" method="POST" action="via.php">
            <input type="submit" name="form1submit" value="submit1"/>
        </form>
        <form name="form12" method="POST" action="via.php">
            <input type="submit" name="form2submit" value="submit2"/>
        </form>
        </td>


  </tr>
</table>

2 个答案:

答案 0 :(得分:4)

根据the specification

,不允许使用嵌套表格
  

Flow content, but with no form element descendants.

w3 validator

中给出此输入
<!DOCTYPE html><html><head><title>tit</title></head><body>
<form action="x">
    <form action="x">
        <input type="submit" value="x"> <!-- Submitting.. Which form...?-->
    </form>
</form>    
</body></html>

w3验证员说:

  

Saw a form start tag, but there was already an active form element. Nested forms are not allowed. Ignoring the tag.

答案 1 :(得分:2)

问题似乎是“HTML文档可以包含多个表单吗?”正确的答案是“是的,只要它们不是嵌套的。”表单将完全不同,每个表单都有一组自己的字段