当我按下提交按钮将数据发送到服务器时使用php,当脚本返回时我需要一个是和否按钮来显示批准或拒绝批准已发送的数据...请帮忙!我迷失在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>
答案 0 :(得分:0)
您需要分三步,而不是两步:
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.