Created
June 23, 2014 18:41
-
-
Save dejanmarkovic/39108995f507d9620a1d to your computer and use it in GitHub Desktop.
Contact form submission with validation done first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment