Strychnine Posted October 9, 2013 Share Posted October 9, 2013 Hello all! I've written a jQuery addMethod for the jQuery validation plugin that seems to be causing an error. Basically this method just checks the db to see if the email address is registered. It works correctly and prompts the error/or passes it correctly. However it fired back an error and sets the focus to the field on submit. If I take this out, the form fires correctly no problem. Any insight I would appreciate. Submit Handler: submitHandler: function(form) { if($("#registerForm").valid()) { $.ajax({ type: "POST", async: false, url: "activate.php", data: $("#registerForm").serialize(), success: function(data) { $('#results').html(data); $('#registerForm').fadeOut(1000); $('#thanks').fadeToggle(1000); } }) } }, addMethod $.validator.addMethod("checkEmailAvailability", function(email) { $('#email').blur(function() { $.ajax({ type: "POST", url: "http://"+location.host+"/includes/checkemail.php?", data: "email=" +$("#email").val(), success: function(data) { if(data == 'false') { //$('#checkEmail').removeClass("validate-ok"); $('#checkEmail').addClass("validate-error").html('✗ ' + $("#email").val() + ' is already a registered email.'); } else { $('#checkEmail').html(''); } } }) }); }); Quote Link to comment https://forums.phpfreaks.com/topic/282840-jquery-addmethod-issue/ Share on other sites More sharing options...
Solution Strychnine Posted October 9, 2013 Author Solution Share Posted October 9, 2013 Seems I figured out what the issues was. I wanted to maintain the same functionality as my method, but as most people say to use the remote method. With that I decided to wrap the remote with a function() that would process the same way, here is my updated code is anyone else has this issue: email: { email: true, required: true, minlength: 8, remote: function() { $('#email').blur(function() { $.ajax({ type: "POST", url: "http://"+location.host+"/includes/checkemail.php?", data: "email=" +$("#email").val(), success: function(data) { if(data == 'false') { $('#checkEmail').addClass("validate-error").html('✗ ' + $("#email").val() + ' is already a registered email.'); } else { $('#checkEmail').html(''); } } }) }); } }, Quote Link to comment https://forums.phpfreaks.com/topic/282840-jquery-addmethod-issue/#findComment-1453298 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.