Jump to content

Jquery Password Validation


Grandioso

Recommended Posts

I'm working on user registration/account management. I want to validate the old user password with AJAX, before the new password is being sent to the php script. So I want to wait for the AJAX to tell me whether the PW is correct or not and then either return false (stop posting the form), or go on. The problem is, the form is always posted. I don't know where to put the 'return false'. I've tried loads of different options, but it still won't work. If anyone could just take a look, it'd be much appreciated.

 

This is how the button.click method looks like:

 

 

{ 
var current_pwd = $( '#current_password' ).attr( 'value' );
var pw_correct = false;
$.ajax({ 
url: ajax_vars.ajax_url,
type: 'POST',
async: false,
data: 'action=check_pw&pw='+current_pwd,
success: function( data ) 
{
pw_correct = data 
}
});
if (!pw_correct)
{ 
alert('wrong pw');
return false; 
}
}

 

I tried to put it in 'complete' and 'success' callbacks, tried with async = true and false, but it still doesn't seem to work.

Link to comment
Share on other sites

You set pw_correct as false. I'm pretty sure that this will trigger the if statement at the bottom before the return of the Ajax function, so you're always going to pass the statement before it gets a chance to be set true.

Edited by Xaotique
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.