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!
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:
It won’t refresh the last page though, but in my opinion it’s even better.
Hope it helps.
Use a JavaScript history trick for the back button.
Here’s a complete discussion why you have to use a JavaScript redirect: https://stackoverflow.com/questions/8046859/how-to-trigger-browsers-back-event-function-using-javascript
Hope it helps!