带有“提交”按钮的表单会导致另一个带有“是/否”按钮的窗体


Form with a submit button that leads to another form with a yes/no button

当我按下提交按钮将数据发送到服务器时,使用php,当脚本返回时,我需要同时出现yes和no按钮来批准或取消批准发送的数据。。。请帮忙!我在if/else-if语句中迷路了

if (filter_has_var(INPUT_POST, "office")){
$office = filter_input(INPUT_POST, "office");
print "<span>, your office is room $office</span>";
}
if (filter_has_var(INPUT_POST, "os")){
$os = filter_input(INPUT_POST, "os");
print "<span>, and your OS is $os</span>";
}
if($_POST['submit']== 'yes'){
    echo "Thanks!";
}elseif($_POST['submit']=='no'){
    return form(); 
}
else{
//there's no input. Create the form 
print <<< HERE
<form action ="" method="post">
<fieldset>
<label>Enter your name</label> 
<input type = "text"
         name = "name"/><br>
<label>Employee ID</label> 
<input type = "text"
         name = "id"/><br>
<label>Office Room Number</label> 
<input type = "text"
         name = "office"/><br>
<label>Oberating System on the Office Computer</label> 
<input type = "text"
         name = "os"/><br>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="yes" value="yes">
<input type="hidden" name="no" value="no">
</fieldset> 
</form>
HERE;
}
// end 'value exists' if
?>
    </body>
</html>

您需要分三步而不是两步来完成:

if (yes or no are set as well as the other required form variables){
   // step 3
   // do final submission
} else if (submit and other required form variables are set){
   // step 2
   // A. display data. 
   // B. display form with only yes/no options and no other visible fields
   // C. in form also include original submitted data (as hidden fields)
} else {
   // step 1
   // display empty form with all fields and a submit button
}

如果希望表单可编辑,可以将第二步更改为组合A和C。