impidimpi
impidimpi

Reputation: 47

PHP Button click call different Pages

I'm trying to create a landing page and there should be one download button. So when the button was clicked and the form has been completed correctly the user will be redirected to the thank you page but when the form has not been completed correctly I will redirect the user to an error page. How can I realize this?

My form

My code for the 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>

My code for the body:

    <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>

Upvotes: 0

Views: 530

Answers (1)

Felipe Valdes
Felipe Valdes

Reputation: 2217

Consider the following, you may redirect the user to a different page using this line of code:

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

also, if you have already sent html output before this line, you can simply emit a javascript redirect:

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

Upvotes: 2

Related Questions