如果符合条件,我想重定向到网页。
如果条件不满足,我已经在使用meta进行重定向。
<meta http-equiv="refresh" content="4; url=form3.html" />
<?php
$to = "example@example.at";
$subject = "School Info";
$headers = "From: Free Project Day";
$field_school = $_POST['school'];
$field_email = $_POST['email'];
$date = date('d/m/Y');
$forward = "1";
$forward2 ="0";
$location = "index.html";
if (empty($field_school) || empty($field_email) && empty($field_tel) ) {
echo 'Please correct the fields';
return false;
if ($forward == 1) {
header ("Location:$location");
}
}
$msg = "TEXT $date.\n\n";
foreach ($_POST as $key => $value) {
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1) {
header ("Location:$location");
}
else {
echo ("TEXT>");
}
?>
我尝试使用$ forward但它没有用。是否有其他方法可以在不使用Meta或$ forward的情况下重定向?
由于
答案 0 :(得分:0)
在
标题(“位置:$ location”);
你需要添加exit();
所以,代码将是
标题(“位置:$ location”); 出口();
让我知道它是否有效!
答案 1 :(得分:0)
根据您发布的代码检查这是否有效。我做了一些编辑。检查所有条件是否也符合您的意图
if ((empty($field_school) || empty($field_email)) && empty($field_tel) )
{
echo 'Please correct the fields';
//return false; No need for this as there's not function here
if ($forward == 1)
{
header('refresh:4;url='.$location);
exit();
}
}
$msg = "TEXT $date.\n\n";
foreach ($_POST as $key => $value)
{
$msg .= ucfirst ($key) ." : ". $value . "\n";
}
mail($to, $subject, $msg, $headers);
if ($forward2 == 1)
{
header('refresh:4;url='.$location);
exit();
}
else {
echo "your messages here";
}