Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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!

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
1  
Thank You Wordpressor: this is what I needed! Appreciate the help! –  PVA Nov 22 '11 at 17:56
    
@PVA, welcome on board. –  Wordpressor Nov 23 '11 at 2:03
add comment

Use a JavaScript history trick for the back button.

<a href="#" onClick="history.back();return false;">Back to Page</a>

Here's a complete discussion why you have to use a JavaScript redirect: http://stackoverflow.com/questions/8046859/how-to-trigger-browsers-back-event-function-using-javascript

Hope it helps!

share|improve this answer
    
Thank You Rutwick, that was helpful! –  PVA Nov 22 '11 at 17:56
    
You're welcome! –  Rutwick Gangurde Nov 23 '11 at 2:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.