1/** 2 * FAU Leads Capture Form JS 3 */ 4 5(function($) { 6 'use strict'; 7 8 /** 9 * Form Handling 10 * Note: UTM parameters are now captured via PHP session 11 */ 12 const fauLeadsForm = { 13 init: function() { 14 this.bindEvents(); 15 }, 16 17 /** 18 * Bind form events 19 */ 20 bindEvents: function() { 21 const self = this; 22 const $form = $('#fau-leads-form'); 23 24 if (!$form.length) return; 25 26 $form.on('submit', function(e) { 27 e.preventDefault(); 28 self.handleSubmit($(this)); 29 }); 30 31 // Clear error messages on input 32 $form.find('input').on('input', function() { 33 $(this).removeClass('error'); 34 $(this).siblings('.error-message').text(''); 35 }); 36 }, 37 38 /** 39 * Client-side validation 40 */ 41 validate: function($form) { 42 let isValid = true; 43 const email = $form.find('#email').val().trim(); 44 const zipCode = $form.find('#zip_code').val().trim(); 45 46 // Clear previous errors 47 $form.find('.error-message').text(''); 48 $form.find('input').removeClass('error'); 49 50 if (!email) { 51 this.showError($form.find('#email'), 'Email is required'); 52 isValid = false; 53 } else if (!this.isValidEmail(email)) { 54 this.showError($form.find('#email'), 'Please enter a valid email address'); 55 isValid = false; 56 } 57 58 if (!zipCode) { 59 this.showError($form.find('#zip_code'), 'ZIP code is required'); 60 isValid = false; 61 } else if (!this.isValidZip(zipCode)) { 62 this.showError($form.find('#zip_code'), 'Please enter a valid 5-digit ZIP code'); 63 isValid = false; 64 } 65 66 return isValid; 67 }, 68 69 showError: function($field, message) { 70 $field.addClass('error'); 71 $field.siblings('.error-message').text(message); 72 }, 73 74 isValidEmail: function(email) { 75 return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email); 76 }, 77 78 isValidZip: function(zip) { 79 return /^[0-9]{5}(-[0-9]{4})?$/.test(zip); 80 }, 81 82 /** 83 * Handle AJAX submission 84 */ 85 handleSubmit: function($form) { 86 if (!this.validate($form)) { 87 return; 88 } 89 90 const $submitBtn = $form.find('button[type="submit"]'); 91 const $responseMsg = $form.find('.fau-leads-form__response-message'); 92 const formData = $form.serialize(); 93 94 $submitBtn.addClass('loading').prop('disabled', true); 95 $responseMsg.hide().removeClass('success error'); 96 97 $.ajax({ 98 url: fauLeads.ajaxUrl, 99 type: 'POST', 100 data: formData + '&action=fau_submit_lead', 101 success: function(response) { 102 if (response.success) { 103 $responseMsg.addClass('success').text('Thank y
103ou! Your information has been submitted.').fadeIn(); 104 $form[0].reset(); 105 } else { 106 const error = response.data && response.data.message ? response.data.message : 'An error occurred. Please try again.'; 107 $responseMsg.addClass('error').text(error).fadeIn(); 108 } 109 }, 110 error: function() { 111 $responseMsg.addClass('error').text('An error occurred. Please try again.').fadeIn(); 112 }, 113 complete: function() { 114 $submitBtn.removeClass('loading').prop('disabled', false); 115 } 116 }); 117 } 118 }; 119 120 $(document).ready(function() { 121 fauLeadsForm.init(); 122 }); 123 124})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.