我想要一个 php 联系表,当提交时(如果没有错误),将刷新同一页面,并删除联系表,并将其替换为一些文本,例如“感谢您与我们联系”。有没有最好的方法来做到这一点?
问问题
95 次
2 回答
2
你总是可以做这样的事情:
<?php
$posted = false;
if( isset($_POST['submit']) ) {
/* Process $_POST */
/* Do your things */
/* Set a variable hinting if a post has been done */
$posted = true;
}
?>
<!DOCTYPE html>
<html>
<body>
<?php if( $posted ): ?>
<form method="post">
<input name="foo" />
<input name="bar" />
<input name="car" />
<input name="submit" type="submit" value="Submit" />
</form>
<?php else: ?>
<h1>Thank you for contacting us!</h1>
<?php endif; ?>
</body>
</html>
于 2013-01-03T23:26:46.280 回答
0
这样做。
<?php
$showform=true; //dispaying the form for the first time
if(isset($_POST['submit'])){
//check for errors
if($errors){
$msg="errors";
$showform=true; // if found errors, setting error msg and displaying the form
}else{
//process the form
$showform=false; //if no errors, setting success msg and hiding the form
$msg="SUccess";
}
}
if(isset($msg)){
//display the success/error msg
echo $msg;
}
if($showform==true){
//your form code
<form method="post">
<input name="foo" />
<input name="bar" />
<input name="car" />
<input name="submit" type="submit" value="Submit" />
</form>
}
?>
于 2013-01-03T23:28:37.137 回答