jQuery + ASP + Validation + ajaxform

I have written some jQuery which is intended to validate a simple html form before sending the form via email using asp. The validation seems to work as the error messages appear on the form but for some reason the form is still being sent if the data entered is not valid. Does anyone have any idea where I am going wrong? TIA
//@Additions by EJS - jQuery + ASP email
//AJAX Sending of ASP
//+ Basic Validation

jQuery(document).ready(function() { 
        var options = {
                beforeSubmit:  showRequest,  // pre-submit callback 
                success:       showResponse  // post-submit callback 
        }; 

        // bind form using 'ajaxForm' 
        jQuery('#contactform').ajaxForm(options); 
});

function showRequest() {

    jQuery("#contactform").validate({
        //set the rules for the field names
        rules: {
            name: {
                required: true,
            },

            mememail: {
                required: true,
                email: true
            },

            message: {
                required: true
            }
        }
    });

    jQuery("#contactform").validate().form();
}

function showResponse() {
    alert("Thanks for your message!");
    disablePopup();
    jQuery('#contactform').clearForm();
}

Open in new window

EdMacFlyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
you need to return either true or false, depending on whether or not the input is valid. So change:
...
 jQuery("#contactform").validate().form();
}

to:
...
return  jQuery("#contactform").validate().form();
}

since the form() method returns true when the form input is valid - false otherwise.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
EdMacFlyAuthor Commented:
Well that was straight forward enough!

How would I change the code so that an alert was fired every time the validation failed?
0
EdMacFlyAuthor Commented:
And thank you :)
0
EdMacFlyAuthor Commented:
Easy to follow and prompt. Good answer.
0
hieloCommented:
>>How would I change the code so that an alert was fired every time the validation failed?
In that case save the returned value of the form() method first. IF it is false, then do the desired alert. At the very end simply return the saved returned value:
...
  var temp =  jQuery("#contactform").validate().form();
  if(!temp)
  {
    alert("Invalid");
  }
return temp;
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.