为什么在这种情况下会出现确认表单重新提交


Why does confirm form resubmission appear in this case?

我有如下代码:

if(isset($_POST["send"])){
$error=0;
//verify if there are any errors (like uncompleted fields)
//if there are errors, $error=1
if($error==0){
//do something then print "DONE";
}
else if($error==1){
//SHOW FORM AGAIN
}
}
else{//IF $_POST["send"] IS NOT SET
//SHOW FORM: <form method="POST" action="<?php echo $_SERVER["PHP_SELF"]?>"> etc.
}

发生的情况是,当我提交没有任何错误的表单并返回时,不会出现"确认表单重新提交"消息,但当提交有错误的时,我会对其进行修改,使其没有错误,然后提交并返回,会出现"确认表单再次提交"消息

为什么会发生这种情况?为什么两种情况都不一样

非常感谢!

编辑您的代码,使其看起来像下面的代码

<?php
$error = 1;
if(isset($_POST["send"])){
$error=0;
//verify if there are any errors (like uncompleted fields)
//if there are errors, $error=1
} else{    //IF $_POST["send"] IS NOT SET
  
//SHOW FORM: <form method="POST" action="<?php echo $_SERVER["PHP_SELF"]?>"> etc.
}
if($error==0){
//do something then print "DONE";
}
elseif($error==1){
//SHOW FORM AGAIN
}
?>

但由于缺乏信息,这不是一个很酷的代码,您需要使用if语句的第一块来检查if post is set the variable $error 来检查验证。