-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
31 lines (25 loc) · 798 Bytes
/
script.js
File metadata and controls
31 lines (25 loc) · 798 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
30
31
const CONFIG = {
WEB3FORMS_KEY: "7cba3acc-6d19-4ae5-8bff-28f9d89d4b0d",
TARGET_URL: "https://example.com",
REDIRECT_URL: "/thanks.html"
};
const form = document.querySelector("#contact-form");
const redirectBtn = document.querySelector("#redirect-btn");
redirectBtn.href = CONFIG.TARGET_URL;
form.addEventListener("submit", async (e) => {
e.preventDefault();
const formData = new FormData(form);
formData.append("access_key", CONFIG.WEB3FORMS_KEY);
const response = await fetch("https://api.web3forms.com/submit", {
method: "POST",
body: formData
});
if (response.ok) {
window.location.href = CONFIG.REDIRECT_URL;
} else {
alert("Something went wrong.");
// see error
const data = await response.json()
console.log(JSON.stringify(data))
}
});