重定向并停留在同一节


redirect and stay at the same section

基本上我想要的是,当我提交表单时,action="被设置为我的PHP脚本,它执行表单并做它需要做的事情,如果不成功,它会重定向到显示错误的同一页面,但当它重定向到页面顶部时,我如何使它自动转到错误显示在该页面上的表单,就像自动滚动一样,有点像^TOP链接,当你点击顶部时,它会转到你设置id的位置。

我只想让它知道错误在页面上的位置,并滚动到该错误,所以客人想知道发生了什么,因为错误在表单附近,而他们在页面的顶部。

为此使用锚点。

<!DOCTYPE html>
<html>
    <head>
        <title>My Page</title>
    </head>
    <body>
        [... stuff on top of the page]
        <div id="errors">My Errors</div>
        <?php var_dump($_GET); ?>
    </body>
</html>

PHP部分

<?php
    header('location: mypage.php?var1=test&var2=test#errors');
?>