2013-02-13 140 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