PHP-在同一页面上连续提交

PHP-在同一页面上连续提交,php,forms,submit,Php,Forms,Submit,我可以连续提交并保持在同一页面上吗 我需要填写一张表格,然后是第二张,然后是第三张,依此类推。。。必须根据答案触发不同的功能和形式。例如: <form method="post"> Sex?<input type="text" name="sex"> <input type="submit" name ="submit_sex" value="Submit"> </form> <?php if(

我可以连续提交并保持在同一页面上吗

我需要填写一张表格,然后是第二张,然后是第三张,依此类推。。。必须根据答案触发不同的功能和形式。例如:

  <form method="post">
       Sex?<input type="text" name="sex">
           <input type="submit" name ="submit_sex" value="Submit">
 </form>


<?php
 if(isset($_POST['submit_sex'])){
         echo("Fist submit done");
      ?>

         <form method="post">
             Age?<input type="text" name="age">
                 <input type="submit" name ="submit_age" value="Submit">
          </form>
     <?php
         if(isset($_POST['submit_age'])){
             echo("Second submit done");
          }
 }
 ?>

性?
年龄?

是的,您可以,但是如果使用Ajax,它看起来会更漂亮/更友好。但是,在您的情况下,使用条件语句来检测要显示的表单会更有效,并且为了绝对最小输入验证,您至少应该检查空值:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <?php
        if(isset($_POST['third_question']) && $_POST['third_question'] != "") {
            // store value of $_POST['third_question'] in a cookie
            // Last question answered, do what you need to next with all the values
        } elseif(isset($_POST['second_question']) && $_POST['second_question'] != "") {
            // store value of $_POST['second_question'] in a cookie
            Third Question? <input type='text' name='third_question' />
        } elseif(isset($_POST['first_question']) && $_POST['first_question'] != "") {
            // store value of $_POST['first_question'] in a cookie, then display next quesion
            Second Question? <input type='text' name='second_question' />
        } else {
            First Question? <input type='text' name='first_question' />
        }
    ?>
    <input type="submit" name="submit" value="Submit" />
</form>

我认为在浏览器端这样做更有意义。你可以这样做:

  <form method="post">
     <div id="sexInput">
       Sex?<input type="text" name="sex" />
           <input type="button" name="submit_sex" value="Submit" onClick="showAge()" />
     </div>
     <div id="ageInput" style="display:none;">
       Age?<input type="text" name="age" />
           <input type="submit" value="Submit" />
     </div>
 </form>

性?
年龄?

还有一个函数
showAge()
,它隐藏sexInput div并显示ageInput div。这样,它实际上是一个表单,在最后一次提交所有表单,但一次只向用户显示一个部分。

你的意思是提交表单并再次提供它吗?我再次上传了代码,并添加了详细信息。但我不知道表单会是什么样子。根据收到的数据,我将进行计算,然后给出适当的表格,以便下一步解决问题。