skevthedev
skevthedev

Reputation: 465

jQuery form validation with available email check

So I have a form that uses the jQuery validation plugin to check the fields before the form can be submitted... pretty basic stuff and that all works fine but I would like the email to also be checked against the database for duplicates.

If one is found then I dont want the form to be submitted obviously and have an error display next to the field. I have tried a couple of things but nothing has worked. Here is my code that validates all the fields.

$(function(){
    $('#myform')
       .validate({
         submitHandler: function(form) {

           $(form).ajaxSubmit({
                success: function() {
                    $('#myForm').append("<p class='thanks'>Thanks!</p>")
                }
           });
         }
      }); 
});

Upvotes: 3

Views: 654

Answers (1)

PetersenDidIt
PetersenDidIt

Reputation: 25620

User the remote method of validation:

$(function() {
    $('#myform').validate({
        rules: {
            email: {
                required: true,
                email: true,
                remote: "check-email.php"
            }
        },
        submitHandler: function(form) {

            $(form).ajaxSubmit({
                success: function() {
                    $('#myForm').append("<p class='thanks'>Thanks!</p>")
                }
            });
        }
    });
});

Upvotes: 4

Related Questions