我正在尝试创建目标网页,应该有一个下载按钮。因此,当单击按钮并且表单已正确完成时,用户将被重定向到感谢页面,但是当表单未正确完成时,我会将用户重定向到错误页面。我怎么能意识到这一点?
我的表格代码:
<form method="post" action="index.php">
<input type="email" name="iptEmail" placeholder="MaxMustermann@gmail.com" 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>
答案 0 :(得分:2)
考虑以下情况, 您可以使用以下代码行将用户重定向到其他页面:
<?php
if(some_condition...){
header("Location: someotherplace.php");
}
另外,如果您已经在此行之前发送了html输出,则只需发出javascript重定向:
<?php
if(some_condition...){
echo("<script>;location.href='someotherplace.php';</script>");
}