1const {__} = wp.i18n; 2 3(function ($) { 4 5 let mietInput = $("#mietvertragsnummer"); 6 if (mietInput.length !== 0) { 7 let cleave = new Cleave(mietInput, { 8 delimiter: '/', 9 blocks: [4, 5, 4, 2], 10 uppercase: true, 11 numericOnly: true, 12 }); 13 } 14 15})(jQuery); 16 17let gewoFormContainer = jQuery('.gewo-form'); 18gewoFormContainer.on('click', '.ajax-form-submit', function (event) { 19 20 let currentForm = gewoFormContainer.children('form'); 21 22 event.preventDefault(); 23 24 let validationResult = gewoValidateForm(); 25 26 let formResponse; 27 28 if (validationResult === true) { 29 30 let data = currentForm.serialize() + "&ajax=1"; 31 32 jQuery.post(currentForm.attr('action'), data); 33 34 formResponse = '' 35 + '<p><strong>' 36 + __('Vielen Dank für Ihr Interesse an der Anmietung einer Wohnung in einem Gewobag Neubauobjekt!', 'gewo-forms') 37 + '</strong></p>' 38 + '<p><b>' 39 + __('Sie erhalten in kürze eine Bestätigungsmail.', 'gewo-forms') 40 + '</b><br>' 41 + __('Um Ihre E-Mail-Adresse und Ihre Einwilligung zu bestätigen, klicken Sie bitte auf den Aktivierungslink. Andernfalls werden Ihre über das Kontaktformular mitgeteilten Daten nach 2 Wochen gelöscht.', 'gewo-forms') 42 + '</p>'; 43 formResponse = jQuery('<div></div>').addClass('message form-success').html(formResponse); 44 45 jQuery('<div></div>').addClass('form-hide').on('click', function (clickEvent) { 46 clickEvent.preventDefault(); 47 jQuery('.form-response > .message').remove(); 48 }) 49 .appendTo(formResponse); 50 51 clearFormInput(currentForm); 52 53 } else { 54 55 formResponse = jQuery('<strong></strong>').html(__('Bitte korrigieren Sie Ihre Angaben.', 'gewo-forms')); 56 formResponse = jQuery('<div></div>').addClass('message form-error').html(formResponse); 57 } 58 59 jQuery('.form-response > .message').remove(); 60 jQuery('.form-response').append(formResponse); 61 62 if (jQuery('.form-response > .form-success').length) { 63 setTimeout(function () { 64 jQuery('.form-response > .message').fadeOut().remove(); 65 }, 15000); 66 } 67 68}); 69 70function gewoValidateForm() { 71 72 jQuery('.error-message').remove(); 73 74 let formValidation = []; 75 76 formValidation.push(gewoValidateField('#title')); 77 formValidation.push(gewoValidateField('#firstname')); 78 formValidation.push(gewoValidateField('#lastname')); 79 formValidation.push(gewoValidateField('#email')); 80 formValidation.push(gewoValidateField('#email_rep')); 81 formValidation.push(gewoValidateField('#ds')); 82 83 return !formValidation.includes(false); 84} 85 86function gewoValidateField(fieldId) { 87 88 let fieldValidation = true; 89 90 let value = jQuery(fieldId).val(); 91 let regEx; 92 let isValid; 93 let customMessage; 94 let isRequiredMessage = __('Bitte füllen Sie dieses Feld aus', 'gewo-forms'); 95 96 switch (fieldId) { 97 98 // texts 99 case '#firstname': 100 case '#lastname': 101 regEx = /[\[\]\{\}\(\)<>;:]/; 102 customMessage = __('Bitte entfernen Sie die unzulässigen Zeichen <strong><>[](){};:</strong>', 'gewo-forms'); 103 104 if (value.length > 0) { 105 isValid = !regEx.test(value); 106 if (!isValid) { 107 appendInputError(fieldId, customMessage); 108 fieldValidation = false; 109 } 110 } 111 break; 112 113 // checkboxes 114 case '#ds': 115 regEx = /[0-9]/; 116 value = jQuery(fieldId).is(':checked') ? jQuery(fieldId).val() : ''; 117 118 if (value.length > 0) { 119 isValid = regEx.test(value); 120 if (!isValid) { 121 fieldValidation = false; 122 } 123 } else { 124 appendCheckboxError(fieldId, isRequiredMessage, 'label[for=ds]'); 125 fieldValidation = false; 126 } 127 break; 128 129 case '#title': 130 regEx = /^[a-zA-Z0-9]+$/i; 131 let title1 = jQuery('#title1').is(':checked') ? jQuery('#title1').val() : ''; 132 let title2 = jQuery('#title2').is(':checked') ? jQuery('#title2').val() : ''; 133 134 if (title1.length > 0 || title2.length > 0) { 135 jQuery('#title1,#title2').each(function () { 136 isValid = regEx.test(this.value); 137 if (!isValid) { 138 fieldValidation = false; 139 } 140 }); 141 } 142 break; 143 144 // email 145 case '#email': 146 regEx = /^[a-zA-Z0-9][a-zA-Z0-9._%+-]{0,63}@(?:[a-zA-Z0-9-]{1,63}\.){1,125}[a-zA-Z]{2,63}$/; 147 customMessage = __('Geben Sie eine gültige E-Mail-Adresse ein', 'gewo-forms'); 148 149 if (value.length > 0) { 150 isValid = regEx.test(value); 151 if (!isValid) { 152 appendInputError(fieldId, customMessage); 153 fieldValidation = false;
154 } 155 } else { 156 appendInputError(fieldId, isRequiredMessage); 157 fieldValidation = false; 158 } 159 break; 160 161 case '#email_rep': 162 customMessage = __('E-Mail-Adressen sind nicht identisch', 'gewo-forms'); 163 let email = jQuery('#email').val(); 164 165 if (value.length > 0) { 166 if (email !== value) { 167 appendInputError(fieldId, customMessage); 168 fieldValidation = false; 169 } 170 } else { 171 appendInputError(fieldId, isRequiredMessage); 172 fieldValidation = false; 173 } 174 break; 175 } 176 177 return fieldValidation; 178} 179 180function appendInputError(inputId, inputMessage) { 181 182 inputMessage = '<div class="error-message">' + inputMessage + '</div>'; 183 184 jQuery(inputId) 185 .change(function () { 186 jQuery(this).next('.error-message').remove(); 187 jQuery('.error-message').length === 0 ? jQuery('.form-error').remove() : ''; 188 }) 189 .after(inputMessage); 190} 191 192function appendCheckboxError(checkboxId, checkboxMessage, checkboxLabel) { 193 194 if (checkboxMessage !== '') { 195 checkboxMessage = '<div class="error-message">' + checkboxMessage + '</div>'; 196 } 197 198 jQuery(checkboxId) 199 .change(function () { 200 jQuery(checkboxLabel).find('.error-message').remove(); 201 jQuery('.error-message').length === 0 ? jQuery('.form-error').remove() : ''; 202 }) 203 .next('strong').after(checkboxMessage); 204} 205 206function clearFormInput(theForm) { 207 theForm.find('#title1').prop('checked', false); 208 theForm.find('#title2').prop('checked', false); 209 theForm.find('#firstname').val(''); 210 theForm.find('#lastname').val(''); 211 theForm.find('#email').val(''); 212 theForm.find('#email_rep').val(''); 213 theForm.find('#ds').prop('checked', false); 214}
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.