learner
learner

Reputation: 4818

Validate a form using jquery.validate before submit

I am trying to validate my form using jquery.validate plugin. It works fine, but when I am trying to submit using form id, it submits invalid form.

Now I validate using:

$("#login_form").validate();

The form id is:

<form role="form" method = "POST" id="login_form"> ... </form>

Now, if validation is not complete, I get an alert using this function:

("#login_form").submit(
    function()
    { 
        alert("Please submit");
    }
    );

I think, I should not get alert unless I validate my form completely. Please help me to solve this.

Upvotes: 0

Views: 7274

Answers (1)

Rayon
Rayon

Reputation: 36609

Read .valid method of jQuery validate

You need to check the form validity inside submit handler and prevent the form submission if valid returns false.

Refer this for .submit()

Upvotes: 3

Related Questions