Skip to content

Commit

Permalink
testing one last thing
Browse files Browse the repository at this point in the history
  • Loading branch information
TFM110 committed Dec 17, 2023
1 parent 09c86df commit 3589795
Showing 1 changed file with 79 additions and 51 deletions.
130 changes: 79 additions & 51 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,83 @@ $(document).ready(function () {
$("#footer").load("footer.html");
});

/**
* Contact Form
*/
const url = 'https://script.google.com/macros/s/AKfycbycwU6StZFD5d1fTHyvpvmyQfKrpSJoYHt2RH94TqviG1CJhSRzGC31_qNNscTqp2LS/exec';
const contactForm = document.getElementById('contact-form');
const loadingMessage = document.querySelector('.loading');
const errorMessage = document.querySelector('.error-message');
const sentMessage = document.querySelector('.sent-message');

contactForm.addEventListener('submit', function (event) {
event.preventDefault();

const recaptchaResponse = document.getElementById('g-recaptcha-response').value;

if (!recaptchaResponse) {
errorMessage.style.display = 'block';
loadingMessage.style.display = 'none'; // Hide loading message
sentMessage.style.display = 'none'; // Hide success message
return;
}

loadingMessage.style.display = 'block'; // Show loading message

const formData = new FormData(this);
const data = Object.fromEntries(formData);
data.gCaptchaResponse = recaptchaResponse;

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8',
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
console.log('Successful', data);
contactForm.reset();
loadingMessage.style.display = 'none'; // Hide loading message
sentMessage.style.display = 'block'; // Show success message
errorMessage.style.display = 'none'; // Hide error message
setTimeout(function () {
sentMessage.style.display = 'none'; // Hide success message after a few seconds
}, 5000);
})
.catch((err) => {
console.log('err', err);
loadingMessage.style.display = 'none'; // Hide loading message
errorMessage.style.display = 'block'; // Show error message
sentMessage.style.display = 'none'; // Hide success message
const url =
'https://script.google.com/macros/s/AKfycbycwU6StZFD5d1fTHyvpvmyQfKrpSJoYHt2RH94TqviG1CJhSRzGC31_qNNscTqp2LS/exec';

document
.getElementById('contact-form')
.addEventListener('submit', function (event) {
event.preventDefault();

const formData = new FormData(this);
const data = Object.fromEntries(formData);

fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'text/plain;charset=utf-8',
},
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
console.log('Successful', data);
this.reset();
})
.catch((err) => console.log('err', err));
});
});



// /**
// * Contact Form
// */
// const url = 'https://script.google.com/macros/s/AKfycbycwU6StZFD5d1fTHyvpvmyQfKrpSJoYHt2RH94TqviG1CJhSRzGC31_qNNscTqp2LS/exec';
// const contactForm = document.getElementById('contact-form');
// const loadingMessage = document.querySelector('.loading');
// const errorMessage = document.querySelector('.error-message');
// const sentMessage = document.querySelector('.sent-message');

// contactForm.addEventListener('submit', function (event) {
// event.preventDefault();

// const recaptchaResponse = document.getElementById('g-recaptcha-response').value;

// if (!recaptchaResponse) {
// errorMessage.style.display = 'block';
// loadingMessage.style.display = 'none'; // Hide loading message
// sentMessage.style.display = 'none'; // Hide success message
// return;
// }

// loadingMessage.style.display = 'block'; // Show loading message

// const formData = new FormData(this);
// const data = Object.fromEntries(formData);
// data.gCaptchaResponse = recaptchaResponse;

// fetch(url, {
// method: 'POST',
// headers: {
// 'Content-Type': 'text/plain;charset=utf-8',
// },
// body: JSON.stringify(data),
// })
// .then((res) => res.json())
// .then((data) => {
// console.log('Successful', data);
// contactForm.reset();
// loadingMessage.style.display = 'none'; // Hide loading message
// sentMessage.style.display = 'block'; // Show success message
// errorMessage.style.display = 'none'; // Hide error message
// setTimeout(function () {
// sentMessage.style.display = 'none'; // Hide success message after a few seconds
// }, 5000);
// })
// .catch((err) => {
// console.log('err', err);
// loadingMessage.style.display = 'none'; // Hide loading message
// errorMessage.style.display = 'block'; // Show error message
// sentMessage.style.display = 'none'; // Hide success message
// });
// });

0 comments on commit 3589795

Please sign in to comment.