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
https://forums.phpfreaks.com/topic/270357-jquery-password-validation/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.