提交后如何进入下一个表单,但它在同一页面上

时间:2017-10-20 21:17:34

标签: html forms

我想根据表单进行调查,在下面的第一个表单上提交后,我尝试获取新的(下一个)表单。

<form id="pass" action="form.html" method="get">
---some code for users to select answers--
<button type="submit" form="nextpass" value="next">
</form>
<form id="nextpass" action="form.html" method="get">

两个表单都显示在同一页面上,但是当我按下一个按钮时,我收到错误“无法获取/”。

1 个答案:

答案 0 :(得分:0)

最简单的方法是为每个提交按钮指定一个唯一的名称。然后检查它是否已提交,并进行相应处理。

<form id="form_1" action="" method="post">
<input type="submit" name="submit_1" value="Submit" />
</form>

<form id="form_2" action="" method="post">
<input type="submit" name="submit_2" value="Submit" />
</form>


<?php

if( $_POST['submit_1'] ) {

// Do stuff

//hide form 1
echo "<style>#form_1{display:none}</style>";
        }
        else if( $_POST['submit_2'] ) {

          // Do stuff

        }

        ?>