2013-02-13 123 views
0

我无法获得我在WordPress网站上创建的自定义表单,它在提交后重定向到“谢谢”页面。表单动作调用一个php函数,它首先通过电子邮件发送表单内容。电子邮件通过罚款。WordPress提交后PHP表单重定向

我的表单标签设置为:

<form id="adoptApp" action="<?php formMailer(); ?>" method="post"> 

和我formMailer功能包含:

if (empty($_POST["applicantName"])) { 
    return; 
} 

$to = "[email protected]"; 

if (empty($_POST["preferredPup"])) { 
    $subject = "Addoption Application"; 
} else { 
    $subject = "Addoption Application for " . $_POST["preferredPup"]; 
} 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: Foo <[email protected]>" . "\r\n"; 
$headers .= "Cc: " . $_POST["applicantEmail"] . "\r\n"; 

$application = adoptionApplicationEmail(); 

mail($to, $subject, $application, $headers); 

php的邮件功能后,我已经尝试使用页面重定向以下方法。所有这些都导致表单只是重新加载,空白。

// Method #1 
$redirectURL = "http://www.bar.org/thanks/"; 
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=' . $redirectURL . '">'; 

// Method #2 
wp_safe_redirect('http://www.bar.org/thanks/'); 

// Method #3 
header("Location: http://www.bar.org/thanks/"); 

最后是感谢页面的代码(以防有用)。

<?php /* Template Name: FormSubmitted_ThankYou */ ?> 
<?php get_header(); ?> 
<?php $myScripts = $_SERVER['DOCUMENT_ROOT'] . 'path/to/scripts.php' ; 
    include $myScripts; 
?> 

<p style="padding: 5px"> 
<b>Thank you!</b><br />You application has been submitted. We will review it as soon as possible.<br /> 
In the meantime if you have any questions you may email us at <a href="mailto:[email protected]">[email protected]</a> 
</p> 

<?php get_footer(); ?> 

我的目的是进一步自定义感谢页面与一些$ _ POST数据,但是我最终停留在这个重定向问题。

回答

0

一个简单的方法来做到这一点如下。

添加您的电子邮件代码的感谢页面这样的:

<?php /* Template Name: FormSubmitted_ThankYou */ 

if (empty($_POST["applicantName"])) { 
    exit(); 
} 

$to = "[email protected]"; 

if (empty($_POST["preferredPup"])) { 
    $subject = "Addoption Application"; 
} else { 
    $subject = "Addoption Application for " . $_POST["preferredPup"]; 
} 

$headers = 'MIME-Version: 1.0' . "\r\n"; 
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= "From: Foo <[email protected]>" . "\r\n"; 
$headers .= "Cc: " . $_POST["applicantEmail"] . "\r\n"; 

$application = adoptionApplicationEmail(); 

mail($to, $subject, $application, $headers); 

get_header(); 

$myScripts = $_SERVER['DOCUMENT_ROOT'] . 'path/to/scripts.php' ; 
include $myScripts; 
?> 

<p style="padding: 5px"> 
<b>Thank you!</b><br />You application has been submitted. We will review it as soon as possible.<br /> 
In the meantime if you have any questions you may email us at <a href="mailto:[email protected]">[email protected]</a> 
</p> 

<?php get_footer(); ?> 

而且你的表单标签改成这样:

<form id="adoptApp" action="http://www.bar.org/thanks/" method="post"> 
+0

完美,谢谢!正如我所希望的那样工作。 – Shawrich 2013-02-13 17:42:51