1document.addEventListener("DOMContentLoaded", function() { 2 const formContainer = document.getElementById("salesforce-foundation-form"); 3 if (!formContainer) return; // Exit if the form isn't on the page 4 5 const form = formContainer.querySelector("form"); 6 const successMessage = formContainer.querySelector("#success-message"); 7 const errorMessage = formContainer.querySelector("#error-message"); 8 9 // --- AJAX Form Submission Logic --- 10 if (form && successMessage && errorMessage) { 11 form.addEventListener("submit", function(event) { 12 event.preventDefault(); // Stop default page reload 13 14 // --- Bootstrap Validation Check --- 15 if (!form.checkValidity()) { 16 event.stopPropagation(); 17 form.classList.add('was-validated'); 18 return; // Stop the submission if fields are invalid 19 } 20 21 // Form is valid, proceed with submission. 22 form.classList.remove('was-validated'); // Clear old validation classes 23 24 const submitButton = form.querySelector('button[type="submit"]'); 25 const formData = new FormData(form); 26 27 // Hide previous messages and update button state 28 errorMessage.style.display = 'none'; 29 successMessage.style.display = 'none'; 30 submitButton.disabled = true; 31 submitButton.textContent = 'Submitting...'; 32 33 fetch(form.action, { 34 method: form.method, 35 body: formData, 36 mode: 'no-cors' // Necessary for Salesforce Web-to-Case 37 }) 38 .then(response => { 39 // Salesforce Web-to-Case with 'no-cors' returns an opaque response. 40 // We assume success if the network request didn't fail. 41 42 form.style.display = 'none'; // Hide the form 43 successMessage.style.display = 'block'; // Show success message 44 45 // --- Reset form on success --- 46 form.reset(); 47 form.classList.remove('was-validated'); 48 }) 49 .catch(error => { 50 // This catches network errors (e.g., user is offline) 51 console.error('Submission error:', error); 52 errorMessage.style.display = 'block'; // Show error message 53 54 // Re-enable the button so the user can try again 55 submitButton.disabled = false; 56 submitButton.textContent = 'Submit'; 57 }); 58 }); 59 } 60});
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.