Hello everyone,
I have a form that is being processed and validated by Jquery. I was just using a post to process the form and serializing it. The only issue is that it would submit into our database in Firefox, Chrome, and Safari but not any version of IE. Now I am using an $AJAX post. I also do not know if I have tied in all of my script together correctly. Any help is appreciated. Here is my scirpt:
<script type="text/javascript">
$(document).ready(function(){
$("#formid").submit(function(event){
event.preventDefault();
submitform();
})
$("#formid").validate({
rules: {
firstname: { required: true },
lastname: { required: true },
phone: { required: true },
email: { required: true, email: true },
relocating_city: {
required: "#relocating:checked"
},
relocating_state: {
required: "#relocating:checked"
}
},
messages: {
firstname: "Please enter your first name",
lastname: "Please enter your last name",
phone: "Please enter your phone number",
email: "Please enter your email address",
relocating_city: "Please enter your relocating city",
relocating_state: "Please enter your relocating state"
},
errorContainer: "#messageBox1",
errorLabelContainer: "#messageBox1 ul",
wrapper: "li", debug:true,
});
});
$("#relocating").click(function() {
$("#relocating_city").valid();
$("#relocating_state").valid();
});
function submitform(){
//$.post('whatever.cfm', {First Name: $('#firstname').val(), Last Name: $('#lastname').val(), Email Address: $('#email').val(), Phone: $('#phone').val(), Zip: $('#zip').val()}, returnResults, 'json');
//This is the old post I was using
//$.post('whatever.cfm', $("#formid").serialize(), returnResults(), 'json');
$.ajax({
type: 'post',
url: 'whatever.cfm',
data: $("#formid").serialize(),
dataType: "json",
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
},
error: function(data) {
$('.result').html(data);
alert('Error.');
},
});
}
// I am not sure if I am tying this into my AJAX post correctly
function returnResults() {
if ($("#formid").valid()) {
$('#formid').hide();
$("#ThankYouDiv").show();
_gaq.push(['_trackEvent', '#formid', 'Submit']);
}
}
</script>
and here is my HTML form
<form method="post" id="formid" action="">
<button class="submit" type="submit">Submit Form</button>
\
</form>
Thanks.