-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontactForm.js
25 lines (24 loc) · 994 Bytes
/
contactForm.js
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
const scriptURL = 'https://script.google.com/macros/s/AKfycbxOksF9_Ul6fVbR9rMnahotuZuvrZEtOGW8z8PtPXo2-qraFBtF8X2Y3b802f7QkiIbBg/exec'
const form = document.forms['submit-to-google-sheet'];
const loadingIndicator = document.getElementById('loading');
form.addEventListener('submit', e => {
e.preventDefault();
loadingIndicator.style.display = 'block';
fetch(scriptURL, { method: 'POST', body: new FormData(form) })
.then(response => {
if (response.ok) {
console.log('Success!', response);
alert('Form Submitted Successfully');
form.reset();
} else {
throw new error('network response was not ok.')
}
})
.catch(error => {
console.error('Error!', error.message);
alert('There was an error submitting the form. ;Please try again');
})
.finally(() => {
loadingIndicator.style.display = 'none';
});
});