doumei7420 2014-11-18 20:05
浏览 72

表单不会重定向到响应页面

Created a form, and it checks for errors with php, but after a successful submission it doesn't redirect to the response page I created (thanks.php). It redirects to the same contact page with the same header and page format, but no actual text and the bodytext div doesn't show up. I just need it to redirect to the response page that I created. Any help?

Here's the code:

<?php
 $firstnameerror=$browsererror=$sexerror=$dateerror=$visiterror=$judgementerror=$emailerror=$emailconfirmerror="";

 if (isset($_GET['submit'])){
        $browser = htmlspecialchars($_GET['browser']);
        $firstname = htmlspecialchars($_GET['firstname']);
        $lastname = htmlspecialchars($_GET['lastname']);
        $sex = htmlspecialchars($_GET['sex']);
        $date = htmlspecialchars($_GET['date']);
        $visit = htmlspecialchars($_GET['visit']);
        $judgement = htmlspecialchars($_GET['judgement']);
        $message = htmlspecialchars($_GET['message']);
        $email = htmlspecialchars($_GET['email']);
        $emailconfirm = htmlspecialchars($_GET['emailconfirm']);

        echo "<p>form submitted</p>";

        if (isset($browser) && isset($firstname) && isset($lastname) && isset($sex) && isset($date) && isset($visit)
          && isset($judgement) && isset($message) && isset($email) && isset($emailconfirm)){
            echo "<p>all fields were submitted</p>";}

        if (empty($firstname)){
            $firstnameerror .= "<div class= 'error'>First name is missing</div>";}

        if (empty($browser)){
            $browsererror .= "<div class= 'error'>Tell us where you're from</div>";}

        if (empty($sex)){
            $sexerror .= "<div class= 'error'>Gender is missing</div>";}

        if (empty($date)){
            $dateerror .= "<div class= 'error'>Date is missing</div>";}

        if (empty($visit)){
            $visiterror .= "<div class= 'error'>Tell us what you visited</div>";}

        if (empty($judgement)){
            $judgementerror .= "<div class= 'error'>Tell us what you thought</div>";}

        if (!empty($email) && empty($emailconfirm)){
            $emailerror .= "<div class= 'error'>Please confirm your email</div>";}

        if ($email != $emailconfirm){
            $emailconfirmerror .= "<div class='error'>Make sure your emails match.</div>";}

      if (empty($browsererror) && empty($firstnameerror) && empty($sexerror) && empty($dateerror) && empty($visiterror) && empty($judgementerror) && empty($emailerror)
          && empty($emailconfirmerror)){
          header('Location: thanks.php');
          exit();
        }
      }
?>

 <div class="bodytext">
  <form method="get" action="contact.php">
    <h2>Feedback</h2>
    <fieldset>
    <div>
    <label for="browser">Who are you?</label> <span style="font-size:10px;color:red">*Required</span><br>
    <input list="browsers" name="browser" placeholder="Click Arrow ->">
    <datalist id="browsers">
      <option value="Visitor">
        <option value="Town Resident">
          <option value="Cornell University Student">
            <option value="Ithaca College Student">
              <option value="Cornell University Professor">
                <option value="Ithaca College Professor">
                </datalist><?php echo $browsererror ?>
                </div><br><br>
                <div>
                <label for="firstname">First name</label> <span style="font-size:10px;color:red">*Required</span><br>
                <input type="text" name="firstname" placeholder="First Name" value="<?php echo $firstname ?>"/><br>
                <?php echo $firstnameerror ?>
              </div>
              <div>
                <label for="lastname">Last name</label><br><input type="text" name="lastname" placeholder="Last Name" value="<?php echo $lastname ?>"/>
              </div><br><br>
              <div>
                <label for="gender">Gender:</label>
                <input type="radio" name="sex" value="Male" checked>Male
                <input type="radio" name="sex" value="Female">Female<br>
                <?php echo $sexerror ?>
              </div><br>
              <div>
                <label for="date">Date of Visit</label> <span style="font-size:10px;color:red">*Required</span><br>
                <input type="date" name="date" min="2014-10-03" max="2014-10-05"><br>
                <?php echo $dateerror ?>
              </div><br>
              <div>
                <label for="visit">What did you visit?</label> <span style="font-size:10px;color:red">*Required</span><br>
                <input type="checkbox" name="visit" value="Fairway Market" checked>Fairway Market<br>
                <input type="checkbox" name="visit" value="Car Show">Car Show<br>
                <input type="checkbox" name="visit" value="First Peoples' Festival">First Peoples' Festival<br>
                <input type="checkbox" name="visit" value="Concerts">Concerts<br>
                <input type="checkbox" name="visit" value="Finger Lakes Cider Week">Finger Lakes Cider Week<br>
                <input type="checkbox" name="visit" value="Apple Pie Bake-off">Apple Pie Bake-off<br>
                <input type="checkbox" name="visit" value="Gallery Night">Gallery Night<br>
                <input type="checkbox" name="visit" value="Other">Other<br>
                <?php echo $visiterror ?>
              </div><br>
              <div>
                <label for="judgement">What did you think?</label> <span style="font-size:10px;color:red">*Required</span><br>
                <input type="radio" name="judgement" value="Loved It" checked>Loved It<br>
                <input type="radio" name="judgement" value="Liked It">Liked It<br>
                <input type="radio" name="judgement" value="Neutral">No Opinion/Neutral<br>
                <input type="radio" name="judgement" value="Didn't Like It">Didn't Like It<br>
                <input type="radio" name="judgement" value="Hated It">Hated It<br>
                <?php echo $judgementerror ?>
              </div><br>
              <div>
                <label for="message">Suggestions/Improvements</label><br>
                <textarea name="message" id="message" placeholder="Type your message here" value="<?php echo $message ?>"/></textarea><br><br>
               </div>
               <div>
                Do you want to be contacted about<br>future Downtown Ithaca Events?<br>
                <label for="email">E-mail:</label>
                <input type="email" name="email" placeholder="Type E-mail" value="<?php echo $email ?>"/><br>
                <label for="emailconfirm">Confirm:</label>
                <input type="email" name="emailconfirm" id="emailconfirm" placeholder="Confirm E-mail" value="<?php echo $emailconfirm ?>"/><br><br>
                <?php echo $emailerror ?><?php echo $emailconfirmerror ?></div>
                <input name="ResponseForm" type="hidden" value="thanks.php"/>
                <button type="submit" name="submit">Submit</button>
                </fieldset>
              </form>
          </div>
          <script src="JS/myscript.js"></script>
        </body>
        </html>
  • 写回答

3条回答 默认 最新

  • dongshijiao6890 2014-11-18 20:10
    关注

    You can't redirect after echoing content. Remove this echo and it will redirect:

    echo "<p>form submitted</p>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?