1jQuery(document).ready(function ($) { 2 function handleRegistration() { 3 const registerForm$ = $('.ghm-register-form'); 4 const firstName$ = registerForm$.find('#ghm_first_name'); 5 const lastName$ = registerForm$.find('#ghm_last_name'); 6 const email$ = registerForm$.find('#ghm_email'); 7 const terms$ = registerForm$.find('#ghm_terms'); 8 const submitBtn$ = registerForm$.find('.ghm-submit-btn'); 9 const errorMessage$ = registerForm$.find('.error-message'); 10 11 let isFirstNameValid = false; 12 let isLastNameValid = false; 13 let isEmailValid = false; 14 let isTermsChecked = false; 15 16 firstName$.on('input', function () { 17 const value = $(this).val().trim(); 18 19 if (value === '') { 20 isFirstNameValid = false; 21 $(this).attr('aria-invalid', 'true'); 22 errorMessage$.filter('#first-name-error').text('First name is required.').attr('hidden', false); 23 } else if (/\d/.test(value)) { 24 isFirstNameValid = false; 25 $(this).attr('aria-invalid', 'true'); 26 errorMessage$.filter('#first-name-error').text('First name cannot contain numbers.').attr('hidden', false); 27 } else if (value.length < 2) { 28 isFirstNameValid = false; 29 $(this).attr('aria-invalid', 'true'); 30 errorMessage$.filter('#first-name-error').text('First name must be at least 2 characters long.').attr('hidden', false); 31 } else if (/\d/.test(value)) { 32 isFirstNameValid = false; 33 $(this).attr('aria-invalid', 'true'); 34 errorMessage$.filter('#first-name-error').text('First name cannot contain numbers.').attr('hidden', false); 35 } else if (/[!@#$%^&*(),.?":{}|<>]/.test(value)) { 36 // Thanks GPT for regex help 37 isFirstNameValid = false; 38 $(this).attr('aria-invalid', 'true'); 39 errorMessage$.filter('#first-name-error').text('First name cannot contain special characters.').attr('hidden', false); 40 } else { 41 isFirstNameValid = true; 42 $(this).attr('aria-invalid', 'false'); 43 errorMessage$.filter('#first-name-error').text('').attr('hidden', true); 44 } 45 46 submitBtn$.prop('disabled', !(isEmailValid && isFirstNameValid && isLastNameValid && isTermsChecked)); 47 }); 48 49 lastName$.on('input', function () { 50 const value = $(this).val().trim(); 51 if (value === '') { 52 isLastNameValid = false; 53 $(this).attr('aria-invalid', 'true'); 54 errorMessage$.filter('#last-name-error').text('Last name is required.').attr('hidden', false); 55 } else if (value.length < 2) { 56 isLastNameValid = false; 57 $(this).attr('aria-invalid', 'true'); 58 errorMessage$.filter('#last-name-error').text('Last name must be at least 2 characters long.').attr('hidden', false); 59 } else if (/\d/.test(value)) { 60 isLastNameValid = false; 61 $(this).attr('aria-invalid', 'true'); 62 errorMessage$.filter('#last-name-error').text('Last name cannot contain numbers.').attr('hidden', false); 63 } else if (/[!@#$%^&*(),.?":{}|<>]/.test(value)) { 64 // Thanks GPT for regex help 65 isLastNameValid = false; 66 $(this).attr('aria-invalid', 'true'); 67 errorMessage$.filter('#last-name-error').text('Last name cannot contain special characters.').attr('hidden', false); 68 } else { 69 isLastNameValid = true; 70 $(this).attr('aria-invalid', 'false'); 71 errorMessage$.filter('#last-name-error').text('').attr('hidden', true); 72 } 73 74 submitBtn$.prop('disabled', !(isEmailValid && isFirstNameValid && isLastNameValid && isTermsChecked)); 75 }); 76 77 email$.on('input', function () { 78 const value = $(this).val().toLowerCase(); 79 // Thanks GPT for regex help 80 const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; 81 if (value === '' || !emailPattern.test(value)) { 82 isEmailValid = false;
83 $(this).attr('aria-invalid', 'true'); 84 errorMessage$.filter('#email-error').text('Not a valid email address.').attr('hidden', false); 85 } else { 86 isEmailValid = true; 87 $(this).attr('aria-invalid', 'false'); 88 errorMessage$.filter('#email-error').text('').attr('hidden', true); 89 } 90 91 submitBtn$.prop('disabled', !(isEmailValid && isFirstNameValid && isLastNameValid && isTermsChecked)); 92 }); 93 94 terms$.on('change', function () { 95 isTermsChecked = $(this).is(':checked'); 96 97 if (!isTermsChecked) { 98 errorMessage$.filter('#terms-error').text('You must agree to the terms and conditions.').attr('hidden', false); 99 } else { 100 errorMessage$.filter('#terms-error').text('').attr('hidden', true); 101 } 102 103 submitBtn$.prop('disabled', !(isEmailValid && isFirstNameValid && isLastNameValid && isTermsChecked)); 104 }); 105 106 if (isFirstNameValid && isLastNameValid && isEmailValid && isTermsChecked) { 107 submitBtn$.attr('disabled', false); 108 } 109 110 registerForm$.on('submit', function (e) { 111 e.preventDefault(); 112 const formData = $(this).serialize(); 113 $.ajax({ 114 type: 'POST', 115 url: GHM.ajax_url, 116 data: { 117 action: GHM.actions.register, 118 data: formData, 119 }, 120 beforeSend: function (response) { 121 submitBtn$.prop('disabled', true); 122 registerForm$.find('.ghm-submit-text').hide(); 123 registerForm$.find('.ghm-spinner').show(); 124 }, 125 complete: function (response) { 126 submitBtn$.prop('disabled', false); 127 registerForm$.find('.ghm-submit-text').show(); 128 registerForm$.find('.ghm-spinner').hide(); 129 turnstile && turnstile.reset(); 130 }, 131 success: function (response) { 132 if (response.success === true) { 133 window.dataLayer = window.dataLayer || []; 134 window.dataLayer.push({ 135 brand: registerForm$.data('brand'), 136 eventType: 'registerSuccess', 137 module: 'BrandedSite', 138 page: window.location.href, 139 sessionID: Cookies.get('GAID') || '', 140 timestamp: new Date().toISOString(), 141 event: 'register', 142 email: response.data.email || '', 143 firstName: response.data.first_name || '', 144 lastName: response.data.last_name || '', 145 source: response.data.source || '', 146 }); 147 148 $('#ghm-register-message').text(`You have successfully registered as ${response.data.first_name} ${response.data.last_name}. Please check your email to activate your account.`); 149 registerForm$.trigger('reset'); 150 } else { 151 $('#ghm-register-message').text('There was an error while trying to register for an account.'); 152 } 153 }, 154 error: function (error) { 155 $('#ghm-register-message').text(error); 156 } 157 }); 158 }); 159 } 160 161 handleRegistration(); 162 163 jQuery(document).on('elementor/popup/show', function (event, id, instance) { 164 handleRegistration(); 165 }); 166});
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.