在窗体之前重定向重定向


Redirect Redirecting before Form Forms

我正试图使用表单(目前使用formoid)来处理和学习PHP,但遇到了一个问题。我正在遵循我看过的教程,但没有任何东西(正确)工作。我有一个简单的重定向脚本,如果某人输入了正确的ID和(六位数)日期,我打算用它将其重定向到一个页面"verified.html",如果没有,则重定向到"no.html"。然而,我尝试的两种方法都不起作用。当我使用这种方法时:

<?php
  if (isset($_POST['submit'])){   
    $id = $_POST['trid'];
    $date = $_POST['trdate'];   
  }
  if ($id == '555555' && $date =='080808') {
    header("Location: http://example.com/Form/verified.html");
    exit();
  }    else {
    header("Location: http://example.com/Form/no.html");
    exit();
  }
 ?>

在加载表单之前,页面会重定向到"no.html"。在阅读了另一个教程后,我认为我必须在"IF(isset)"语句中包含两个IF语句

 <?php
 if (isset($_POST['submit'])){   
    $id = $_POST['trid'];
    $date = $_POST['trdate'];   
    if ($id == '555555' && $date =='080808') {
      header("Location: http://example.com/Form/verified.html");
       exit();
    }  else {
       header("Location: http://example.com/Form/no.html");
       exit();
    }
 }

表单实际上会加载,但无论我输入和提交什么,它都不会重定向到任何地方。我昨晚整晚都在处理这个问题,并摆弄不同的解决方案,我想到的一切要么会导致表单没有加载,要么它被加载,然后在输入时没有重定向。如果有人能给我指明正确的方向,那就太棒了。如果相关的话,下面是表单页面的代码(我在开头包含了redirect.php,因为如果我在其他地方包含它,我会收到一个关于header()的错误):

 <?php
    include "redirect.php";
 ?>
 <html>
 <head>
    <meta charset="utf-8" />
    <title>Verify</title>
    <meta name="viewport" content="width=device-width, initial-   scale=1.0">
 </head>
 <body class="blurBg-false" style="background-color:#EBEBEB">
 <!-- Start Formoid form-->
 <link rel="stylesheet" href="formoid_files/formoid1/formoid-solid-blue.css" type="text/css" />
 <script type="text/javascript" src="formoid_files/formoid1/jquery.min.js"></script>
<form action="validate.php" class="formoid-solid-blue" style="background-color:#FFFFFF;font-size:14px;font-family:'Roboto',Arial,Helvetica,sans-serif;color:#34495E;max-width:480px;min-width:150px" method="post"><div class="title">      <h2>Patient Verification</h2></div>
    <div class="element-input"><label class="title">Please enter the six digit ID below:</label><div class="item-cont"><input class="large" type="text" name="trid" id="trid" placeholder="Input Number"/><span class="icon-place"></span></div></div>
    <div class="element-input"><label class="title">Please enter the six digit year MMDDYY below:</label><div class="item-cont"><input class="large" type="text" name="trdate" id="trdate" placeholder="Input Number"/><span class="icon-place"></span></div></div>
    <div class="submit"><input type="submit" value="Submit"></div></form>
    <p class="frmd"><a href="http://example.com/v29.php">form builder</a> Formoid.com 2.9</p><script type="text/javascript" src="formoid_files/formoid1/formoid-solid-blue.js"></script>
 <!-- Stop Formoid form-->
 </body>
 </html>

看起来您的外观是$_POST['submit']已经设置,但您的按钮元素上没有name="submit"。你为什么不使用。。。

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){   
   $id = $_POST['trid'];
   $date = $_POST['trdate'];   
if ($id == '555555' && $date =='080808') {
  header("Location: http://example.com/Form/verified.html");
   exit();
}  else {
   header("Location: http://example.com/Form/no.html");
   exit();
}
}

将html页面中的表单替换为:

<form action="validate.php" class="formoid-solid-blue" style="background-color:#FFFFFF;font-size:14px;font-family:'Roboto',Arial,Helvetica,sans-serif;color:#34495E;max-width:480px;min-width:150px" method="post"><div class="title">      
    <h2>Patient Verification</h2></div>
    <div class="element-input">
        <label class="title">Please enter the six digit ID below:</label>
            <div class="item-cont">
                <input class="large" type="number" name="trid" id="trid" placeholder="Input Number"/>
                <span class="icon-place"></span>
            </div>
    </div>
    <div class="element-input">
        <label class="title">Please enter the six digit year MMDDYY below:</label>
        <div class="item-cont">
            <input class="large" type="number" name="trdate" id="trdate" placeholder="Input Number"/>
            <span class="icon-place"></span>
        </div>
    </div>
    <div class="submit"><input type="submit" name="submit" value="Submit"></div>
</form>

和php

 <?php
    if (isset($_POST['submit'])){  
        $id = $_POST['trid'];
        $date = $_POST['trdate'];   
        if ($id == '555555' && $date =='080808') {
          header("Location: http://example.com/Form/verified.html");
        }  else {
           header("Location: http://example.com/Form/no.html");
        }
    }
?>

看看这个,让我知道结果。

尝试使用这个:

<?php
if (isset($_POST['submit'])){   
    $id = $_POST['trid'];
    $date = $_POST['trdate'];   
}
global $id, $date;
if ($id == '555555' && $date =='080808') {
    header("Location: http://example.com/Form/verified.html");
    exit();
} else {
    header("Location: http://example.com/Form/no.html");
    exit();
}
?>