3

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>
User014019
  • 1,215
  • 8
  • 34
  • 66

2 Answers2

3

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

Community
  • 1
  • 1
Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56
  • what if it will go back to the page where the user came from but in the specific portion of the page? – User014019 Oct 27 '16 at 07:06
  • if your previous page URL were something like this www.yoursite.com/somePage#someSection then the above solution will infact take your to that specific portion of the page. – Abdul Wasae Oct 27 '16 at 07:11
  • the previous page where like this www.yoursite.com/somePage/ and the page that will go back will be like this www.yoursite.com/somePage/#somesection – User014019 Oct 27 '16 at 07:48
  • but when the user came back to the previous page is not in the form, instead in the section after form – User014019 Oct 27 '16 at 08:08
0

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>
Abdul Wasae
  • 3,614
  • 4
  • 34
  • 56
Vikram Biwal
  • 2,618
  • 1
  • 25
  • 36