Is it possible to wrap html form elements in multiple form tags?

倖福魔咒の 提交于 2019-12-01 05:39:05

问题


Would it be wrong to have every element of a form wrapped in <form> tags in an HTML page? Am curious as to why it would be wrong:

Basically I have to introduce two forms(form1 and form2) and there are some elements associated with the first while others with the second.The layout has to be completely table based and since the elements of both forms are all over the page here is what i wrote(according to http://validator.w3.org/check, the code is valid):

<!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>


回答1:


Nested forms are not allowed, according to the specification:

Given this input in the 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>

The w3 validator says:




回答2:


The question appears to be “Can an HTML document contain several forms?” The correct answer is “Yes, as long as they are not nested.” The forms will be completely distinct, each with a set of fields of its own.



来源:https://stackoverflow.com/questions/9433264/is-it-possible-to-wrap-html-form-elements-in-multiple-form-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!