我有一个在同一个 url 中提交的表单(例如 form.co.uk 是表单所在的位置,并且在成功提交而不是转到具有不同 URL 的确认页面时,它会停留在 form.co.uk 上并给出“感谢您在同一页面上联系我们的确认。
但是我需要更改它,以便在提交时转到不同的网址(只是感谢页面)
我该怎么办?
html
<div class="width-inner">
<?if ($c->submitted && count($c->errors) == 0): ?>
<div class="thankyou-box">
<h2>Thank you for your enquiry</h2>
<h3>We'll get back to you as soon as we can.</h3>
</div>
<script type="text/javascript">
_gaq.push(['_trackPageview', "/thanks"]);
</script>
<? else: ?>
<div class="contact-box left" style="width:650px;">
<form action="form.php" method="post">
<div class="heading">
<h2>Contact Us</h2>
<h3>Get in touch now.</h3>
</div>
<? if(count($c->errors) > 0): ?>
<div class="error">
There was a problem with your enquiry
</div>
<? endif; ?>
<div class="vspace20"></div>
<label>Your Name:</label>
<input type="text" name="name" class="<?= $c- >requestEmpty('name') ? 'invalid' : '' ?>" value="<?= @$_REQUEST['name'] ?>"/>
<div class="required">Required field</div>
<div class="clear"></div>
<label>Email Address:</label>
<input type="email" name="email" class="<?= $c- >requestEmpty('email') ? 'invalid' : '' ?>" value="<?= @$_REQUEST['email'] ?>"/>
<div class="required">Required field</div>
<div class="clear"></div>
<hr/>
<label>Enquiry:</label>
<textarea name="enquiry" class="<?= $c->requestEmpty('enquiry') ? 'invalid' : '' ?>">I would like to contact you.</textarea>
<div class="clear"></div>
<hr/>
<input type="hidden" name="extra" value="<?= @$_REQUEST['extra'] ?>"/>
<div class="notice">Your details will not be used for marketing purposes</div> <br>
<input type="submit" class="btn-submit right" value="Claim Now" name="submit"/>
<div class="clear"></div>
</form>
</div>
</div>
处理程序的代码
<?php
class Contact {
var $submitted = false;
var $errors = array();
var $template = "Name: %s\r\nEmail Address: %s\r\nEnquiry: %s";
public function __construct() {
if (!empty($_REQUEST['submit'])) {
$this->submitted = true;
} else {
return;
}
$requiredFields = array(
'name', 'email'
);
foreach($requiredFields as $key) {
if ($this->requestEmpty($key)) {
$this->errors[] = $key;
}
}
if (count($this->errors) == 0) {
$this->_sendForm();
}
}
private function _sendForm() {
$body = sprintf($this->template,
$_REQUEST['name'],
$_REQUEST['email'],
$_REQUEST['enquiry'] . "\r\n" . $_REQUEST['extra']);
$headers = 'From: auto@magnetikmedia.co.uk' . "\r\n" .
'Reply-To: auto@magnetikmedia.co.uk' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail("johnfarrell2012@gmail.com", "New contact form", $body, $headers, "- fauto@magnetikmedia.co.uk");
header("Location: thank_you.php");
exit;
}
public function requestEmpty($key) {
if (empty($_REQUEST['submit'])) {
return false;
}
if (!isset($_REQUEST[$key])) {
return true;
}
if (trim($_REQUEST[$key]) == "") {
return true;
}
return false;
}
}
?>
我想这一定与上面的 if else 语句有关。我想说'如果成功并且没有错误,然后去 www.whatever.com' 但我该怎么写呢?