作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在提交表单后的那一刻,使用以下代码:
<?php
if(isset($error))
{echo "<span id='Warning'>Please enter all areas marked with *</span>";}
else if (isset($sent))
{echo "<span id='Normal'>Thank you for your enquiry, we will contact you shortly</span>";}
?>
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" id="enquiryform">
header('Location: THANK YOU PAGE');
<?php
/* Accessing SQL-Server and querying table */
MYSQL_CONNECT($server, $user, $password) or die ("Server unreachable");
MYSQL_SELECT_DB($database) or die ("Database non existent");
if(array_key_exists('submit',$_POST))
{
$adate = $_POST['adate'];
$guests = $_POST['guests'];
if($guests=="Please Select")
{
$error['guests'] = 'Flagged';
}
$title = $_POST['title'];
if($title=="Please Select")
{
$error['title'] = 'Flagged';
}
$name = trim($_POST['fullname']);
if(empty($name))
{
$error['name'] = 'Flagged';
}
$telephone = trim($_POST['telnumber']);
if(empty($telephone))
{
$error['telephone'] = 'Flagged';
}
$accomm = trim($_POST['accommodation']);
if($accomm=="Default")
{
$error['accommodation'] = 'Flagged';
}
$email = $_POST['email'];
$pattern = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
if (!preg_match($pattern, trim($email)))
{
$error['email'] = 'Flagged';
}
$message = trim($_POST['message']);
//initialize variables
$to = 'EMAIL@EMAILADDRESS.COM';
$subject = "Enquiry";
//build the message
$email_message .= 'Arrival Date: '.$adate.' Guests: '.$guests.' Accom: '.$accomm."\n\n";
$email_message .= 'Name: '.$title.' '.$name."\n\n";
$email_message .= 'Telephone: '.$telephone."\n\n";
$email_message .= 'Email: '.$email."\n\n";
$email_message .= 'Message: '.$message;
$additionalHeaders = "From: XXXXXXXXXXXX<".$email.">";
//print_r($error);
//send the email
if (!isset($error))
{
mail($to, $subject, $email_message, $additionalHeaders);
MYSQL_QUERY("INSERT into Enquiry VALUES('".date('d/m/y')."','".$_POST['hSpa']."','".$_POST['hPackage']."','".$adate."','".$guests."','".$accomm."','".$title."','".$name."','".$telephone."','".$email."','".$message."')");
}
}
?>
</head>
<body id="body">
<form action="<?php echo $_SERVER['../PHP_SELF']; ?>" method="post" id="enquiryform">
<p>Areas marked with * must be completed</p>
<label class="enquiryform" id="message" for="message">Message</label>
<textarea name="message" id="message" rows="9" cols="55" tabindex="9" onclick="removeDefaultText(this)"><?php if(isset($error)) {echo $message;} else {echo "Please use this area for any other information about your enquiry";}?></textarea>
<input type="submit" id="submit" name="submit" value="Send enquiry" tabindex="10" />
</form>
</div>
<?php
if(isset($error)) {
echo "<span id='Warning'>Please enter all areas marked with *</span>";
}
else if (isset($sent)) {
header("Location: THANK YOU PAGE.HTML");
exit();
}
?>
</div>
最佳答案
你可以设置这样的函数:
function pageRedirect ($page) {
if (!@header("Location: ".$page))
echo "\n<script type=\"text/javascript\">window.location.replace('$page');</script>\n";
exit;
}
<?php
if(isset($error))
echo "<span id='Warning'>Please enter all areas marked with *</span>";
else
pageRedirect ($thankyoupage);
?>
关于php - 成功提交时重定向php表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5210624/
我是一名优秀的程序员,十分优秀!