So I've since learned this is not the best way to submit a form, but I'm still wondering why it's getting sent twice, even when the console.log
s are only triggering once, and my ajax .php
file attempts to set a $_SESSION
variable to true, and check if its true, before sending emails (less important though -- why is it even calling the php file twice to begin with?)
html
<form id="SAR_FORM">
//elements
<a href="javascript:void(0)" id="form_SUBMIT" tabindex="8">Submit</a>
</form>
js
$('#form_SUBMIT').click(function(){
console.log('ok');
formErrors = false;
//error Checking
if (!formErrors){
var serialized = $("#SAR_FORM").serialize();
$.post( "ajax/landing/landingForm_ajax.php", serialized, function( data ) {
console.log('loop');
$( "#sec4_errorRow" ).html( data );
if ($("#sec4_errorRow").html() == '.'){
$( "#sec4_errorRow" ).html( '<span style="color:#1eb252; font-weight:400;">Thank you for contacting us! We will be in touch shortly.</span>' );
$( "#form_submit_holder" ).html( '<div id="thanks">Thank You!</div>' );
}
});
}
});