-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
29 lines (25 loc) · 897 Bytes
/
Copy pathscripts.js
File metadata and controls
29 lines (25 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
document.getElementById("contactForm").addEventListener("submit", async function(event) {
event.preventDefault();
// Collect form data
const formData = new FormData(this);
const data = Object.fromEntries(formData.entries());
// Google Sheets URL
const googleScriptURL = "YOUR_GOOGLE_SCRIPT_URL_HERE";
// Send form data to Google Sheets
try {
const response = await fetch(googleScriptURL, {
method: "POST",
mode: "no-cors",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: new URLSearchParams(data),
});
// Optional: Add code here to send email notification
alert("Message sent successfully!");
this.reset();
} catch (error) {
alert("Error sending message.");
console.error("Error:", error);
}
});