简体   繁体   English

重定向到用户来自的页面

[英]Redirect to the page where user came from

I have a custom page template with a form. 我有一个带表单的自定义页面模板。 And this form displayed in many pages using shortcode. 此表单使用短代码显示在许多页面中。 When the user click the submit button, the user will redirect to a "Thank you" page. 当用户单击提交按钮时,用户将重定向到“谢谢”页面。 This thank you page is a static (created using the WP page editor) with a href . 这个感谢页面是一个带有a href的静态(使用WP页面编辑器创建)。 Now, when the user click that a href (found in the thank you page, he/she will redirect to the page url where the user submit the form but in the specific portion of the page where the user came from. But I don't know how to do this. Can anyone help me with this? 现在,当用户点击a href (在感谢页面中找到时,他/她将重定向到用户提交表单的页面URL,但是在用户来自的页面的特定部分。但我不知道我知道怎么做。有人可以帮我这个吗?

<form method="POST">
    <span class="icon-pp-green-ribbon"></span>
    <fieldset>
        <div class="form-group">
            <label for="customer_fname"><span class="icons-asterisk"></span> Your name:</label>
            <input type="text" name="name_first" placeholder="" required/>
        </div>
        <div class="form-group">
            <label for="customer_tsname"><span class="icons-asterisk"></span> Your surname:</label>
            <input type="text" name="name_last" placeholder="" required/>
        </div>
        <div class="form-group">
            <label for="email">Your e-mail:</label>
            <input type="email" name="email" placeholder="@"/>
        </div>
        <div class="form-group">
            <label for="phone"><span class="icons-asterisk"></span> Phone number:</label>
            <input type="text" name="phone" pattern ="^09\d{9}$" onkeypress="return isNumberKey(event)" size="11" placeholder="09" required/>
        </div>
        <div style="margin-top: 1.50em;">
            <input type="checkbox" id="utm_checked" checked style=" float: left; transform: scale(1.2);"/>
            <label for="utm_checked">I want to be occasionally notified</label>
        </div>
        <div class="form-group">
        <input type="submit" name="submit" value="Send"/>
        </div>
    </div>
</form>

Try this button maybe as told here : 试试这个按钮可能在这里说

<input action="action" type="button" value="Back" onclick="window.history.go(-1); return false;" />

If your previous page URL does not have page section info like www.yoursite.com/somePage#someSection , you can push custom URL to the history stack before leaving that page, so that whenever your go back, you not only go back to the page but also the specific portion that you came from. 如果您的上一页网址没有www.yoursite.com/somePage#someSection等网页版块信息,您可以在离开该页面之前将自定义网址推送到历史记录堆栈,这样每当您返回时,您不仅会返回页面,但也是您来自的特定部分。 You can push custom URL to the history stack maintained by the browser as described here 您可以将自定义URL推送到浏览器维护的历史堆栈, 如此处所述

Try this code to utilize page visit history maintained by the browser: 尝试使用此代码来利用浏览器维护的页面访问历史记录:

<button onclick="goBack()">Go Back</button>

<script>
function goBack() {
    window.history.back();
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM