dejanmarkovic
6/23/2014 - 6:41 PM

Contact form submission with validation done first

Contact form submission with validation done first

function setup_contact_form()
{
    $("form#contact").validate(
        {
            rules: {
                cfname: {
                    minlength: 2,
                    required: true
                },
                clname: {
                    minlength: 2,
                    required: true
                },
                cemail: {
                    required: true,
                    email: true
                },
                cmessage: {
                    minlength: 2,
                    required: true
                }
            },
            highlight: function(label) {
                jQuery(label).closest('.control-group').addClass('error');
            },
            success: function(label) {
                //valid = true;
                //alert('valid1');
                jQuery(label)
                    .closest('.control-group').addClass('success');
            }
        });

}

function contactSubmit()
{
        jQuery('form#contact').submit(function(e) {
            setup_contact_form();
            var valid = jQuery('form#contact input, form#contact select').valid();
            e.preventDefault();
            if (valid) {
                jQuery.ajax({
                    type: "POST",
                    url: "https://dashdev.pie247.com/api/apiContactRequest.php",
                    /* url: "https://ip.jsontest.com/", */
                    data: jQuery("form#contact").serialize(),
                    dataType: "html",
                    cache: false
                }).done(function(result) {
                     alert('Done!');
                    $('#submit5').attr('disabled', 'disabled');
                }).fail(function(result) {
                    alert('Please Try Again.');
                });
            }
        })//closing click
}//closing makeCall