这个地方有时是一个真正的救星,所以感谢大家努力让这个地方变得如此伟大。 但是,我有一个问题在这里找不到答案。
我有一个网站,主页上有联系表格,一些内页有联系表格。 我需要每个人都重定向到不同的感谢页面(用于PPC转换跟踪目的(
内页的那个工作正常,提交信息和重定向,但主页上的那个只提交信息,没有重定向。 每个表单都使用一个单独的 php 文件作为表单操作和一个单独的感谢页面。 这是代码,你能看到问题吗? 我想这可能与标题有关?
主页代码:
<form action="landing-page-form.php" method="post">
<h2>Get A Quote Today!</h2>
<p><label for="name">Name</label><input name="name" id="name"></p>
<p><label for="tel">Tel</label><input name="tel" id="tel"></p>
<p><label for="email">Email</label><input name="email" id="email"></p>
<p><label for="service">Service</label><select name="service" id="service"><option value="Kitchen Design">Kitchen Design</option><option value="Bathroom Design">Bathroom Design</option><option value="Central HEating">Central Heating</option><option value="Appliances">Kitchen Appliances</option><option value="Brochure Request">Free Brochure Request</option><option value="Home Visit Request">Free Home Visit Request</option></select></p>
<p><input type="checkbox" name="chk" id="chk" value="1"> <label class="chk" for="chk">check the checkbox</label></p>
<p><button name="submit" type="submit">Send My Enquiry!</button></p>
</form>
这是相关的 php
<?php if ($_POST) {
header('Content-type: application/json');
$fields = array();
$msg = array();
foreach($_POST as $k=>$v) $_POST[$k] = trim($v);
$pattern = "/^[a-zA-Z0-9][a-zA-Z0-9'.-_]+'@([a-zA-Z0-9_-]+'.)+[a-zA-Z]+$/";
if(preg_match($pattern, $_POST['email'])) $email_ok = true;
else $email_ok = false;
if(!$_POST['email'] || !$email_ok) $fields[] = "email";
if(!$_POST['name']) $fields[] = "name";
if(!$_POST['tel']) $fields[] = "tel";
if(count($fields)) {
$status = "error";
if(!$_POST['name'] || !$_POST['email'] || !$_POST['email']) $msg[] = "Please specify your name, telephone and email address.";
if(!$email_ok) $msg[] = "Provided e-mail address is invalid.";
$message = implode("<br>", $msg);
$response['msgStatus'] = $status;
$response['message'] = $message;
$response['errorFields'] = $fields;
} else {
$mailContent = "Name: {$_POST['name']}'ntel: {$_POST['tel']}'nE-mail: {$_POST['email']}'nService: {$_POST['service']}'nCheckbox: {$_POST['chk']}";
$ok = mail("email@email.com", "Message from Home Page Landing Page Form", $mailContent, "From:<".$_POST['email'].">");
if($ok) {
$response['msgStatus'] = "ok";
header( 'Location: /thanks.php' ) ;
} else {
$response['msgStatus'] = "error";
$response['message'] = "Could not send your request due to an error.";
}
}
echo json_encode($response);
}?>
这是内页 HTML:
<form action="quick-contact-form.php" method="post">
<h6>Quick Contact</h6>
<p><label for="name">Name</label><input name="name" id="name"></p>
<p><label for="tel">Tel</label><input name="tel" id="tel"></p>
<p><label for="email">Email</label><input name="email" id="email"></p>
<p><label for="service">Service</label><select name="service" id="service"><option value="Kitchen Design">Kitchen Design</option><option value="Bathroom Design">Bathroom Design</option><option value="Heating">Central Heating</option><option value="Appliances">Kitchen Appliances</option><option value="Brochure Request">Free Brochure Request</option><option value="Home Visit Request">Free Home Visit Request</option></select></p>
<p><input type="checkbox" name="chk" id="chk" value="1"> <label class="chk" for="chk">check the checkbox</label></p>
<p><button name="submit" type="submit">Send!</button></p>
</form>
以及相关的 PHP
<?php if ($_POST) {
header('Content-type: application/json');
$fields = array();
$msg = array();
foreach($_POST as $k=>$v) $_POST[$k] = trim($v);
$pattern = "/^[a-zA-Z0-9][a-zA-Z0-9'.-_]+'@([a-zA-Z0-9_-]+'.)+[a-zA-Z]+$/";
if(preg_match($pattern, $_POST['email'])) $email_ok = true;
else $email_ok = false;
if(!$_POST['email'] || !$email_ok) $fields[] = "email";
if(!$_POST['name']) $fields[] = "name";
if(!$_POST['tel']) $fields[] = "tel";
if(count($fields)) {
$status = "error";
if(!$_POST['name'] || !$_POST['email'] || !$_POST['email']) $msg[] = "Please specify your name, telephone and email address.";
if(!$email_ok) $msg[] = "Provided e-mail address is invalid.";
$message = implode("<br>", $msg);
$response['msgStatus'] = $status;
$response['message'] = $message;
$response['errorFields'] = $fields;
} else {
$mailContent = "Name: {$_POST['name']}'ntel: {$_POST['tel']}'nE-mail: {$_POST['email']}'nService: {$_POST['service']}'nCheckbox: {$_POST['chk']}";
$ok = mail("email@email.com", "Message from Website Landing Page Form", $mailContent, "From:<".$_POST['email'].">");
if($ok) {
$response['msgStatus'] = "ok";
header( 'Location: /thankyou.php' ) ;
} else {
$response['msgStatus'] = "error";
$response['message'] = "Could not send your request due to an error.";
}
}
echo json_encode($response);
}?>
任何和所有的帮助,建议,反馈感谢。
首先,检查您正在使用的路径,并尝试使其绝对,而不是相对的。其次,检查你的.htaccess文件 - 也许有一些讨厌的重写规则。
顺便问一下,你有不同的重定向页面可以吗? header( 'Location: /thanks.php' ) ;
和header( 'Location: /thankyou.php' ) ;
?