Skip to content
- Choosing a selection results in a full page refresh.
- Opens in a new window.
console.log("🚀 Script Loaded! Waiting for form...");
(function() {
function attachFormListener() {
let form = document.querySelector("#29019"); // Replace with actual form ID
if (!form) {
console.warn("⏳ Form not found yet. Retrying...");
setTimeout(attachFormListener, 1000); // Retry after 1s
return;
}
console.log("✅ Form found! Attaching event listener...");
form.addEventListener("submit", function(event) {
event.preventDefault(); // Prevent default form submission
console.log("📤 Form submitted! Preparing data...");
let formData = {
firstName: document.querySelector("input[name='firstName']")?.value || "",
lastName: document.querySelector("input[name='lastName']")?.value || "",
phone: document.querySelector("input[name='phone']")?.value || "",
email: document.querySelector("input[name='email']")?.value || "",
reason: document.querySelector("textarea[name='reason']")?.value || ""
};
console.log("📄 Captured Form Data:", formData);
// Fetch User's IP Address
fetch("https://api64.ipify.org?format=json")
.then(response => response.json())
.then(data => {
formData.ip = data.ip;
console.log("🌐 User IP Address:", formData.ip);
// Send data to Google Sheets
return fetch("https://script.google.com/macros/s/AKfycbw23aXDM2urkTieU4Cz4LIwi_NwIvp4597Ibwst3Vt2bkd-xoKrQbIXq_DtFLpHWtfy/exec", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(formData)
});
})
.then(response => response.text())
.then(data => {
console.log("✅ Data sent successfully:", data);
alert("🎉 Form submitted successfully!");
form.reset(); // Reset form fields after submission
})
.catch(error => console.error("❌ Error sending data:", error));
});
}
document.addEventListener("DOMContentLoaded", attachFormListener);
})();