1/** 2* PHP Email Form Validation - v3.5 3* URL: https://bootstrapmade.com/php-email-form/ 4* Author: BootstrapMade.com 5*/ 6(function () { 7 "use strict"; 8 9 let forms = document.querySelectorAll('.php-email-form'); 10 11 forms.forEach( function(e) { 12 e.addEventListener('submit', function(event) { 13 event.preventDefault(); 14 15 let thisForm = this; 16 17 let action = thisForm.getAttribute('action'); 18 let recaptcha = thisForm.getAttribute('data-recaptcha-site-key'); 19 20 if( ! action ) { 21 displayError(thisForm, 'The form action property is not set!') 22 return; 23 } 24 thisForm.querySelector('.loading').classList.add('d-block'); 25 thisForm.querySelector('.error-message').classList.remove('d-block'); 26 thisForm.querySelector('.sent-message').classList.remove('d-block'); 27 28 let formData = new FormData( thisForm ); 29 30 if ( recaptcha ) { 31 if(typeof grecaptcha !== "undefined" ) { 32 grecaptcha.ready(function() { 33 try { 34 grecaptcha.execute(recaptcha, {action: 'php_email_form_submit'}) 35 .then(token => { 36 formData.set('recaptcha-response', token); 37 php_email_form_submit(thisForm, action, formData); 38 }) 39 } catch(error) { 40 displayError(thisForm, error) 41 } 42 }); 43 } else { 44 displayError(thisForm, 'The reCaptcha javascript API url is not loaded!') 45 } 46 } else { 47 php_email_form_submit(thisForm, action, formData); 48 } 49 }); 50 }); 51 52 function php_email_form_submit(thisForm, action, formData) { 53 fetch(action, { 54 method: 'POST', 55 body: formData, 56 headers: {'X-Requested-With': 'XMLHttpRequest'} 57 }) 58 .then(response => { 59 return response.text(); 60 }) 61 .then(data => { 62 thisForm.querySelector('.loading').classList.remove('d-block'); 63 if (data.trim() == 'OK') { 64 thisForm.querySelector('.sent-message').classList.add('d-block'); 65 thisForm.reset(); 66 } else { 67 throw new Error(data ? data : 'Form submission failed and no error message returned from: ' + action); 68 } 69 }) 70 .catch((error) => { 71 displayError(thisForm, error); 72 }); 73 } 74 75 function displayError(thisForm, error) { 76 thisForm.querySelector('.loading').classList.remove('d-block'); 77 thisForm.querySelector('.error-message').innerHTML = error; 78 thisForm.querySelector('.error-message').classList.add('d-block'); 79 } 80 81})();
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.