2017-09-19 50 views
0

我想創建一個登錄頁面,應該有一個下載按鈕。所以當點擊按鈕並且表單已經正確完成時,用戶將被重定向到感謝頁面,但是當表單沒有正確完成時,我會將用戶重定向到錯誤頁面。我怎麼能意識到這一點?PHP按鈕點擊調用不同的頁面

My form

我對錶單代碼:

<form method="post" action="index.php"> 
    <input type="email" name="iptEmail" placeholder="[email protected]" required /> 
    <br /><br /> 
    <img id="captcha" src="/securimage/securimage_show.php" alt="CAPTCHA Image" /> 
    <a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false"><img src="img/reloadCaptcha.png" alt="reloadCaptcha.png"></a> 
    <br /><br /> 
    <input type="text" name="captcha_code" id="iptCaptcha" placeholder="Code" size="10" minlength="6" maxlength="6" required /> 
    <br /><br /> 
    <button name="btnSubmit">DOWNLOAD</button> 
    <?php 
    include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; 
    $securimage = new Securimage(); 
    if(array_key_exists('btnSubmit',$_POST)){ 
     if ($securimage->check($_POST['captcha_code']) == false) { 
      $_SESSION['status'] = "error"; 
     } else { 
      if(isset($_POST['btnSubmit'])){ 
       $mailKunde = $_POST['iptEmail']; 
       $betreff = ""; 
       $message = ""; 
       $absName = ""; 
       $absMail = ""; 
       $replyTo = ""; 
       $anhang = "./data/test.zip"; 
       mail_att($mailKunde, $betreff, $message, $absName, $absMail, $replyTo, $anhang); 
       $_SESSION['status'] = "thanks"; 
      } 
     } 
    } 
    ?> 
</form> 

我的身體碼:

<body> 
    <?php 
    if ($_SESSION['status'] == "home") { 
     include('php/home.php'); 
    } elseif ($_SESSION['status'] == "error") { 
     include('php/error.php'); 
    } elseif ($_SESSION['status'] == "thanks") { 
     include('php/thanks.php'); 
    } 
    ?> 
</body> 
+2

通過驗證的數據,然後做基於條件的重定向。請更新您的問題,以便在[**最小,完整和可驗證的示例**](http://stackoverflow.com/help/mcve)中顯示**相關代碼**。如果你能讓我們知道你有什麼[**嘗試到目前爲止**](http://meta.stackoverflow.com/questions/261592)來解決你的問題,這也會很有幫助。有關詳細信息,請參閱有關[**如何提出良好問題**](http://stackoverflow.com/help/how-to-ask)的幫助文章,並參加該網站的[**遊覽**](http://stackoverflow.com/tour)) –

+0

確定我有更新我的文章。 – impidimpi

回答

2

考慮以下, 您可以使用將用戶重定向到一個不同的頁面這行代碼:

<?php 
if(some_condition...){ 
    header("Location: someotherplace.php"); 
} 

另外,如果您已發送HTML輸出這一行之前,你可以簡單地發出JavaScript重定向:

<?php 
if(some_condition...){ 
    echo("<script>;location.href='someotherplace.php';</script>"); 
} 
+0

非常有幫助謝謝:) – impidimpi