Skip to content

Commit

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

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
});



// /**
// * 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 9d9da8e

Please sign in to comment.