0

I'm using fancybox to show WordPress login form. It works perfectly. However, if the user enters incorrect user name or password, he is redirected to wp-login.php, but I want the validation will take place within the fancybox window.

How can I do it?

0

You can create a custom ajax action or add a custom parameter to your post request and catch it on init action callback. In that ajax action/init callback you can use wp_signon function to check if the credentials are ok and return proper response. I would write some code but I'm on mobile and would take too much. You can see here an example made with ajax http://fellowtuts.com/wordpress/wordpress-ajax-login-and-register-without-a-plugin/

  • Thanks for the example. Can you help me with a simple code? I would like to refresh the page when the user submit the login form. – user1443216 Aug 31 '16 at 16:48
  • function myCallback(){ if( isset($_POST['mycustomaction'])){ /* process login here using wp_signon */ } } add_action('init', 'myCallback'); – theodorhanu Aug 31 '16 at 20:26
  • Then simply submit fancybox form to yoursiteurl.com/currentDisplayedPage?mycustomaction=1 for example or include a hidden input in your form with name mycustomaction. – theodorhanu Aug 31 '16 at 20:26
  • Example form: <form method="POST" action="<?php echo get_home_url() //here you can use current url or whatever you want ?>"> <input type="hidden" name="mycustomaction" value="1"> <?php wp_nonce_field('nonce_action','nonce_field_name') ?> ..other fields here: username, password, sumbit button.. </form> – theodorhanu Aug 31 '16 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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