0

i am using the jQuery Validation Plugin using data-validate

For example for email validation i am using the following code

<input type="text" name="email" id="email" value=""
                       class="input-text validate-email-exist required-entry form-control"
                       data-validate="required,email"
                       data-message-required="error message here for required"
                       data-message-email="error message here for email"                          
                >

I would like to check if email already exist and as far as i know i have to use the remote method, but i dont know how to make it work

I tried to add the rule

$('input.validate-email-exist').rules("add", {
    remote : {
        url: 'check-email.php',
        type : 'post',
        success: function(data) {
            if (data !== 'true')
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    },
    messages: {
        remote: "custom remote message"
    }
});

but while the ajax call it takes place and return true or false the error message is not displaying at all.

Any help appreciated

Sparky
  • 98,165
  • 25
  • 199
  • 285
Ntan
  • 59
  • 5
  • Why not show us your `check-email.php` function? The `true` / `false` is supposed to be echo'd back from the server as JSON encoded string and the plugin picks it up automatically. There is no need to redundantly examine with `success`. Please refer to plugin documentation and other SO questions for proper usage. – Sparky Jan 05 '21 at 17:30
  • Also, where did you call the `.validate()` initialization method? There seems to be a lot you have not shown us. – Sparky Jan 05 '21 at 23:30

0 Answers0