$(function(){ let sending = false; const form = $('.contactFormFields'); const btn = $('.contactFormFields .submitBtn'); const msg = $('.contactForm .msg'); btn.click(function(e){ e.preventDefault(); if(sending) return; // reset msg.removeClass('visible success error warning'); $('.redBorder').removeClass('redBorder'); let valid = true; // validate required fields $('.contactFormFields [required]').each(function(){ if(!$(this).val().trim()){ $(this).addClass('redBorder'); valid = false; } }); if(!valid){ msg.html("Please fill in all required fields.").addClass('error visible'); return; } // validate email fields $('.contactFormFields input[type=email]').each(function(){ if(!$(this).val().isEmail()){ $(this).addClass('redBorder'); valid = false; } }); if(!valid){ msg.html("Please enter a valid email address.").addClass('error visible'); return; } // send sending = true; btn.html("SENDING..."); $.ajax({ url: 'https://felicia.ca/wp-content/themes/feliciaCA2026/sendContact.php', type: 'POST', data: form.serialize(), success: function(response){ if(response == '-ok-'){ msg.html("Thank you! Your message has been sent.").addClass('success visible'); $('.contactFormFields .clear').val(''); } else { msg.html(response).addClass('error visible'); } btn.html("SUBMIT"); sending = false; } }); }); });