简体   繁体   中英

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 . 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?

<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. You can push custom URL to the history stack maintained by the browser as described here

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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