How code a redirect back to page from form thanks

I building a site in WordPress (my own theme) that includes a very simple “sign up” email form. Person enters name and email address and hits submit button. Client currently using a script through Bluehost so I want to recreate vs. using a form plugin.

The form is fine. After hitting “submit” person is redirected to a “Thank You” page. I would like to be able to add a “back to page” link after the “Thank You for signing up” message that would take them back to whatever page they were on (the form will be on most site pages).

Read More

Tried adding this to the template:

    <?php
$url = htmlspecialchars($_SERVER['HTTP_REFERER']);
echo "<a href='$url'>Back to Page</a>";
?>

but it generates an error message because it’s kicking back to Bluehost, not to the original page.

Can anyone help?

Thanks!

Related posts

Leave a Reply

2 comments

  1. There’s a great function called wp_redirect(), unfortunately not supporting “last page” argument yet, but I hope it will soon.

    I believe the easiest (but not the most elegant way) way to achieve what you need is by using JavaScript, in jQuery it will look like:

    <script type="text/javascript">
       jQuery(document).ready(function() {
          jQuery('#back-link').click(function() {
             history.go(-1) 
           });
       });
    </script> 
    <a href="#" id="back-link">Go back</a>
    

    It won’t refresh the last page though, but in my opinion it’s even better.

    Hope it helps.