Grandioso Posted November 6, 2012 Share Posted November 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270357-jquery-password-validation/ Share on other sites More sharing options...
codefossa Posted November 7, 2012 Share Posted November 7, 2012 (edited) 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 November 7, 2012 by Xaotique Quote Link to comment https://forums.phpfreaks.com/topic/270357-jquery-password-validation/#findComment-1390683 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.