1function onBootstrap() { 2 // Check if endpoint is set 3 if (wp.wp_sls_forms_endpoint.length === 0) { 4 // Display debug message for logged in users 5 if (wp.is_user_logged_in.length !== 0) { 6 console.log("WP Serverless Forms is installed but no endpoint is set."); 7 } 8 return; 9 } 10} 11 12function success(el) { 13 el.target.submit.disabled = false; 14 el.target.querySelector('input[type="submit"]').blur(); 15 el.target.reset(); 16 17 // Redirect if set 18 if (wp.wp_sls_forms_redirect.length > 0) { 19 window.location.replace(wp.wp_sls_forms_redirect); 20 } 21} 22 23function error(el) { 24 el.target.querySelector('input[type="submit"]').disabled = false; 25 alert("Oops! There was an error."); 26} 27 28function submitForm(method, url, data, el) { 29 var xhr = new XMLHttpRequest(); 30 xhr.open(method, url); 31 xhr.onreadystatechange = function () { 32 if (xhr.readyState !== XMLHttpRequest.DONE) return; 33 if (xhr.status === 200) { 34 success(el); 35 } else { 36 error(el); 37 } 38 }; 39 40 xhr.send(data); 41} 42 43function modifyFormAttributes(form) { 44 form.removeAttribute("action"); 45 form.removeAttribute("method"); 46 form.removeAttribute("enctype"); 47 form.removeAttribute("novalidate"); 48 form.setAttribute("data-wp-sls-forms", true); 49} 50 51onBootstrap(); 52 53document.addEventListener("DOMContentLoaded", function () { 54 const allForms = document.querySelectorAll( 55 "form[data-shifter='true'], .wpcf7 form, .wpcf7-form, .gform_wrapper form, .wpforms-container form" 56 ); 57 58 allForms.forEach((form) => { 59 modifyFormAttributes(form); 60 61 // Inputs 62 const inputs = form.querySelectorAll("input"); 63 64 // Add HTML required attribute 65 inputs.forEach((input) => { 66 if (input.getAttribute("aria-required") === "true") { 67 input.required = true; 68 } 69 }); 70 71 form.addEventListener("submit", function (el) { 72 el.preventDefault(); 73 var data = new FormData(form); 74 submitForm("POST", wp.wp_sls_forms_endpoint, data, el); 75 }); 76 }); 77});
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.