• I’m having a little trouble with a custom login form that I’ve created.

    <?php if (!(current_user_can('level_0'))){ ?>
      <div class="login-form">
        <form action="<?php echo get_option('home'); ?>/wp-login.php" method="post" target="_blank">
          <p>
            <label for="log" id="user">Username</label>
        <input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="20" />
          </p>
          <p>
            <label for="password" id="pass">Password</label>
            <input type="password" name="pwd" id="pwd" size="20" />
          </p>
            <input type="submit" name="submit" value="Login" class="button" />
          <p>
            <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label>
            <input type="hidden" name="redirect_to" value="<?php bloginfo('url');?>/login-tournament/tournaments/"/>
         </p>
        </form>
      </div>
      <div id="recovertext"><a href="<?php echo get_option('home'); ?>/wp-login.php?    action=lostpassword">Recover password</a></div>
      <div id="loginbox"><a href="<?php bloginfo('url'); ?>/register">Not registered yet?</a></div>
    <?php } else { ?>
      <p class="login-text">You're already logged in.<br>Click here to view the <a href="https://MY-CUSTOM-REDIRECT-URL.com" target="_blank">Tournaments</a> page or you can <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout"> Logout</a></p>
    <?php }?>

    A successful login will redirect the user to a custom URL and open the custom url in a new window. (this is working fine)

    The problem I have is that if the user enters the incorrect credentials, they are redirected to the default wp-login.php form. I need the user to stay on the current page and display an error message. I did find this snippet to prevent the redirect and it does work but it opens up the same page in a new window. Is it possible to prevent the new window opening when the incorrect details are entered. (I still need the new window to open on successful logins)

    Further to this, if no login details are entered at all when the login button is clicked, it will also send the user to the default wp-login.php page. Is it possible to prevent this also?

Viewing 4 replies - 1 through 4 (of 4 total)
  • wp_redirect usually redirects (via php header-function) to a page in the same window/tab.

    Did you try your site on a different pc/ browser?

    Thread Starter braderz31

    (@braderz31)

    Hi thanks for the response.

    Maybe I wasn’t particularly clear in my original question. The code above is a custom login form that I’ve created. When a user submits a successful login, I want it to redirect to a custom page – this all works fine.

    It’s only when the incorrect details are entered, I want it to ignore the target="_blank and stay on the same page.

    Thanks

    The moment the user pushs the submit-button a new window will open. After this it is not possible to redirect to the old one.

    The are some possibilities
    -you can add some javascript to automatically close the window (window.close(); maybe it does not work, because it ist not a scrip-generated page)
    -Hide the Login if already loged in
    -use Ajax to test if already loged in

    Moderator bcworkz

    (@bcworkz)

    Never mind, in Aachen got it covered while I was distracted else where. I then posted without re-checking for new posts.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Prevent redirect on custom wordpress login form when incorrect details are enter’ is closed to new replies.