Go back two pages and refresh
-
Hello,
I have a login page on the frontend of my website. When a user is reading an article and wants to rate it or comment on it they need to log in so they go to the login page. After one is logged in they end up on the login page which now says : “You have successfully logged in”.
However I’d like them to be brought back to the article they were reading instead of the renew login page. How can I best do this?
I tried to do it using Javascript with window.history.go(-2). That gets the user back to the article page but there is a small problem. I have a menu button linking to the log in page saying: “Log in”. When an user is logged in the text of the button changes to “Log out”.
After window.history.go(-2) the button still says “Log in” instead of “Log out”. After I refresh the page (F5) the correct button appears.
So what I am looking for is a way to go back two pages and then refresh the page.
Or is there a way I can add the document.referrer URL as hidden field to the form and send them back to it?
Thanks in advance!
Here’s my code for the form:
// login form fields function rcp_login_form_fields( $args = array() ) { global $post; if (is_singular()) : $pageURL = get_permalink($post->ID); else : $pageURL = 'http'; if ($_SERVER["HTTPS"] == "on") $pageURL .= "s"; $pageURL .= "://"; if ($_SERVER["SERVER_PORT"] != "80") $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"]; else $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; endif; // parse the arguments passed $defaults = array ( 'redirect' => $pageURL, 'class' => 'rcp_form' ); $args = wp_parse_args( $args, $defaults ); // setup each argument in its own variable extract( $args, EXTR_SKIP ); ob_start(); do_action('rcp_before_login_form'); if(!is_user_logged_in()) { // show any error messages after form submission rcp_show_error_messages(); ?> <form id="rcp_login_form" class="<?php echo $class; ?>" method="POST" action="<?php echo $pageURL; ?>"> <fieldset class="rcp_login_data"> <p> <label for="rcp_user_Login"><?php _e('Username', 'rcp'); ?></label> <input name="rcp_user_login" id="rcp_user_login" class="required" type="text"/> </p> <p> <label for="rcp_user_pass"><?php _e('Password', 'rcp'); ?></label> <input name="rcp_user_pass" id="rcp_user_pass" class="required" type="password"/> </p> <p class="rcp_lost_password"><a href="/register"><?php _e('Not yet a member? Join us now!', 'rcp'); ?></a></p> <p class="rcp_lost_password"><a href="https://www.upoker.nl/wachtwoord-vergeten"><?php _e('Forgot your password?', 'rcp'); ?></a></p> <p> <input type="hidden" name="rcp_action" value="login"/> <input type="hidden" name="rcp_redirect" value="<?php echo $redirect; ?>"/> <input type="hidden" name="rcp_login_nonce" value="<?php echo wp_create_nonce('rcp-login-nonce'); ?>"/> <input id="rcp_login_submit" type="submit" value="Login"/> </p> </fieldset> </form> <?php } else { echo __('You are succesfully logged in.', 'rcp') . ' <a href="' . wp_logout_url(home_url()) . '">' . __('Log out', 'rcp') . '</a>'; } do_action('rcp_after_login_form'); return ob_get_clean(); }
- The topic ‘Go back two pages and refresh’ is closed to new replies.