【问题标题】:Redirect to New Page after Post Action发布操作后重定向到新页面
【发布时间】:2019-02-01 20:27:43
【问题描述】:

目前,当我提交表单时,“申请成功”文本会出现在同一页面上。如何获取表单以提交到感谢页面?

这是我的代码:

    <div role="form" class="col-lg-8" id="wpcf7-f4-p7902-o1" dir="ltr" lang="en-US">
        <form action="<?php echo $apply_permalink; ?>" method="post">
            <?php if($post_saved){ ?>
                <div class="alert alert-success">Application Successful.</div>
            <?php }?>
            <p>
                <label> Your Name &amp; Surname (required)<br>
                    <span class="wpcf7-form-control-wrap your-name">
                        <input name="your-name" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" aria-required="true" aria-invalid="false" type="text">
                    </span> 
                </label>
            </p>
            <p>
                <label> Your Email (required)<br>
                    <span class="wpcf7-form-control-wrap your-email">
                        <input name="your-email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-email" aria-required="true" aria-invalid="false" type="email">
                    </span>
                </label>
            </p>
            <p>
                <label> Your Cell Number<br>
                    <span class="wpcf7-form-control-wrap">
                        <input name="your-cell" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-email wpcf7-validates-as-required wpcf7-validates-as-number" aria-required="true" aria-invalid="false" type="text">
                    </span>
                </label>
            </p>
            <p>
                <input value="Apply" class="wpcf7-form-control" type="submit">
            </p>
        </form>
    </div>

我尝试查看其他有相同问题的提交,但代码与我的不同,因此解决方案不适用于我的。

提前致谢。

【问题讨论】:

  • 感谢您的帮助,我做出了您建议的更改,并且表单正确重定向到新页面。再次感谢!

标签: php html forms redirect form-submit


【解决方案1】:
header("Location: http://www.yourwebsite.com/user.php"); /* Redirect browser */
exit();

最好在后面调用 exit(),这样它下面的代码就不会被执行。

【讨论】:

    【解决方案2】:
    <?php
    if(isset($_POST['submitForm'])){
             header('location: https://google.com/');
             exit();
    }
    ?>
    

    重要的是你把它放在页面的最顶部,否则你可以使用JS

     <?php
        if(isset($_POST['submitForm'])){
                 echo "<script>window.location.href='https://google.com';</script>";
        }
        ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多