2014-03-12 21 views
0

我有一個文本的HTML文件input fields,radio buttonsselect boxes。當用戶提交完成的表單時,它使用POST並將這些數據發送到郵件腳本,然後發送所需的電子郵件。PHP郵件scripr確認

但現在我想在我的主html文件和郵件腳本之間添加一個確認頁面。用戶必須能夠看到他們輸入的數據,並且會有兩個名爲「繼續」和「後退」的按鈕。繼續將發送郵件,然後將用戶帶回到html文件。

我已經搜索了很多解決方案,但找不到一個好的解決方案。我如何使用php來做到這一點。這裏的問題是我可以將數據獲取到確認頁面,但如果用戶單擊繼續,則無法將其發送到郵件腳本。

+0

我有另外一個問題,這是一個動態的形式。所以數據是彼此不同的。一個人可能有一個名爲year的選項,但另一個人可能會有一個名爲school的選項。那麼我該如何處理這種情況。我只想顯示與用戶相關的內容 – user3409278

回答

0

如果您只想使用PHP,可以完成。在您處理表單並通過電子郵件發送的頁面上,您可以使用簡單的if語句。

例如,

If(isset($_POST['submit'])){ 

    echo "make another form here that will be displayed that they have to submit to confirm" 

} 

elseif(isset($_POST['confirm'])){ 

echo "they confirmed and here is where we put the code to send the email." 

} 
else{ 

echo "they did no click submit and we can use a header to send them back to the original page." 


} 
0

你可以這樣做。

在確認頁面中,表單的action屬性應該指向郵件腳本頁面。即:<form action="mail.php">

和按鈕 「繼續」 和 「取消」 應該是這樣的:

<input type="submit" value="Proceed"/>

<input type="button" value="Cancel" onclick="window.location.href='main-file.html'"/>

請注意按鈕 「類型」。

0

這可能有助於

文件message.php

<form action="preview.php" method="post"> 

    <input type="text" name="email"> 
    <input type="text" name="subject"> 
    <textarea name="message"></textarea> 

    <input type="submit" value="Continue"> 
</form> 

文件preview.php

<form action="send.php" method="post"> 

    <input type="hidden" name="email" value="<?php echo $_POST['email'];?>"> 
    <input type="hidden" name="subject" value="<?php echo $_POST['subject'];?>"> 
    <input type="hidden" name="message" value="<?php echo $_POST['message'];?>"> 
    Email: <?php echo $_POST['email'];?> 
    <br/> 
    Subject: <?php echo $_POST['subject'];?> 
    <br/> 
    Message: <?php echo $_POST['message'];?> 

    <input type="submit" value="Send"> 
    <a href="message.php" title="Back">Back</a> 
</form> 

文件send.php

<?php 
if(isset($_POST['email'])){ 

    mail($_POST['email'],$_POST['subject'],$_POST['message']; 
    echo 'Message sent successfully';  
}else{ 
    header('Location: message.php'); 
} 
?> 
+0

此解決方案有效,但我有另一個問題,它是一個動態表單。所以數據是彼此不同的。一個人可能有一個名爲year的選項,但另一個人可能會有一個名爲school的選項。那麼我該如何處理這種情況。我只想顯示與用戶相關的內容 – user3409278

+0

如果(isset($ _ POST ['subject'])){?> 「> <?php echo $ _POST ['subject']; }?> –

+0

非常感謝。我也解決了它。我有最後一個問題。這在Firefox上正常工作。但鉻以某種方式緩存了一些數據並弄亂了確認頁面。我有解決方案嗎? – user3409278