$("#contactForm").submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); /*if($('#name').val() == ""){ $('.help-block.name').html('Please enter your name'); return false; }*/ /* Send the data using post */ var data = $('#contactForm').serialize(); $.ajax({ type: "POST", url: "/contact-us", data: data, cache: false, success: function(result){ if(result == 'SUCCESS'){ $('#successModal').modal('toggle'); $("#successModal .modal-body").html('Thanks '+$('#name').val()+'! Message received'); document.getElementById("contactForm").reset(); $("#contactForm").find('textarea,input').trigger('input'); $('.help-block').html(''); } else { result = JSON.parse(result); if(typeof result['validation_errors'] != "undefined"){ for(var key in result['validation_errors']) { if (!result['validation_errors'].hasOwnProperty(key)){ continue; } else { console.log(key) $('#'+key).next('.help-block').html(result['validation_errors'][key]); $('.help-block').css('color','#c40000'); } } } else { alert(result['error']); } } }, error: function(){ $("#success").html('Sorry '+ $('#name').val() +', it seems that my mail server is not responding. Please try again later!'); $("#success").addClass('alert alert-danger'); } }); }); $("#subscribeForm").submit(function(event) { /* stop form from submitting normally */ event.preventDefault(); /* Send the data using post */ var data = $('#subscribeForm').serialize(); $.ajax({ type: "POST", url: "/contact-us", data: data, cache: false, success: function(result){ if(result == 'SUCCESS'){ $('#successModalNewsletter').modal('toggle'); document.getElementById("subscribeForm").reset(); $('.help-block').html(''); } else { result = JSON.parse(result); if(typeof result['validation_errors'] != "undefined"){ for(var key in result['validation_errors']) { if (!result['validation_errors'].hasOwnProperty(key)){ continue; } else { $('#mc-'+key).next('.help-block').html(result['validation_errors'][key]); $('.help-block').css('color','#c40000'); } } } else { alert(result['error']); } } }, error: function(){ $("#mce-error-response").html('Sorry, it seems that my mail server is not responding. Please try again later!'); } }); });