Help with form valdiation plugin and ajax submit

Help with form valdiation plugin and ajax submit

Sorry everybody, complete noob here learning jquery.

So I'm using this jquery.validator.js plugin, to validate my form, and also, submitting the form to a php script with the ajax call.

Here's my js code.

<script type="text/javascript">
$(document).ready(function() {
   $("#form").validate({
         //set the rules for the fild names
         rules: {
            name: {
               required: true,
               minlength: 2
            },
            comment: {
               required: true,
               minlength: 2
            },
         },
         //set messages to appear inline
         messages: {
            name: "Please enter your name",
            comment: "Please enter your message"
         }
      });
   $('#form').ajaxForm(function() {
   $('#tagline').html('Thanks');
    $('#message h2').html('You submitted your comment');
   $('#tagline').hide();   
   $('#submit_button').hide();   
   $(this).delay(2000,function(){
   window.location = '/';
            });
});
});


Now what happens, when I hit submit on the form, you see the validation error, telling you to type in the form, but right after that, the form gets submitted.

I'm sure my code is all jacked, but what would be the best way, so the ajax call isn't initiated until the form is validated (filled out)?

Thanks