简体   繁体   中英

How to submit a form using jQuery Validate submitHandler

this is jQuery submit form code. what i like to know is how can i submit the form on using submitHandler. thanks in advance.

submitHandler: function(form) {
    // do other stuff for a valid form
    $.post('thankyou.php', $("#confrom").serialize(), function(data) {
        $("#confrom").fadeOut('fast', function(){
            $('#results').html(data);
        });
    });
}

There is a submitHandler built into the plugin that contains something like form.submit() . Since you're over-riding that with your own custom submitHandler , you still need to use the submit . Otherwise, in your case, simply do some kind of Ajax instead of .submit() .

The submitHandler goes inside of the .validate() method. In order to use the .validate() method, you must first include the jQuery Validate plugin after you include jQuery.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.13.1/jquery.validate.js"></script>

<script>
$(document).ready(function() {
    $('#yourform').validate({
        // other options,
        submitHandler: function(form) {
            // do other stuff for a valid form
            $.post('thankyou.php', $(form).serialize(), function(data) {
                $("#confrom").fadeOut('fast', function(){
                    $('#results').html(data);
                });
            });
        }
    });
});
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM