Simple Custom rule for Jquery validator

Posted by thatweblook on Stack Overflow See other posts from Stack Overflow or by thatweblook
Published on 2010-04-13T09:28:31Z Indexed on 2010/04/13 9:33 UTC
Read the original article Hit count: 373

Hi,

I read your reply regarding the jQuery validator where you outline a method to check a username against a value in a database.

Ive tried implementing this method but no matter what is returned from the PHP file I always get the message that the username is already taken.

Here is ths custom method...

$.validator.addMethod("uniqueUserName", function(value, element) {
  $.ajax({
      type: "POST",
       url: "php/get_save_status.php",
      data: "checkUsername="+value,
      dataType:"html",
   success: function(msg)
   {
      // if the user exists, it returns a string "true"
      if(msg == "true")
         return false;  // already exists
      return true;      // username is free to use
   }
 })}, "Username is Already Taken");

And here is the validate code...

username: {
required: true,
uniqueUserName: true

},

Is there a specific way i am supposed to return the message from php.

Thanks

A

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX