-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_script_17.js
More file actions
163 lines (69 loc) · 2.83 KB
/
inline_script_17.js
File metadata and controls
163 lines (69 loc) · 2.83 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const resetBtn = document.querySelector('.btn-secondary');
const contactForm = document.getElementById('contactForm');
const emailForm = document.getElementById('emailForm');
resetBtn.addEventListener('click', function() {
const textInputs = contactForm.querySelectorAll('input[type="text"], input[type="email"], input[type="tel"], textarea');
for (const input of textInputs) {
input.value = ''; // Clearing the input value
}
});
const submitContactFormBtn = document.getElementById('submitContactForm');
submitContactFormBtn.addEventListener('click', async function(event) {
event.preventDefault();
const emailInput = contactForm.querySelector('input[type="email"]');
const emailValue = emailInput.value.trim();
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emailValue === '' || !emailRegex.test(emailValue)) {
emailInput.classList.remove('is-valid');
emailInput.classList.add('is-invalid');
return;
} else {
emailInput.classList.remove('is-invalid');
emailInput.classList.add('is-valid');
}
const formData = new FormData(contactForm);
const url = 'https://script.google.com/macros/s/AKfycbzd19Lr4aju-TLwqwLiCel6o0aLpUnOsbm2CqQTktBtavYktq6lF0l27iD7Hnqd912JOw/exec';
try {
const response = await fetch(url, {
method: 'POST',
body: formData
});
if (!response.ok) {
const errorData = await response.json();
if (response.status === 400 && errorData.error === 'Duplicate email found') {
alert('This email address has already been submitted.');
} else {
console.error('Server Error:', errorData.error);
alert('Failed to submit email.');
}
return;
}
alert('Email submitted successfully!');
contactForm.reset();
} catch (error) {
console.error('Client Error:', error);
alert('An error occurred while submitting the email.');
}
});
const submitEmailFormBtn = document.getElementById('submitEmailForm');
submitEmailFormBtn.addEventListener('click', async function(event) {
event.preventDefault();
const formData = new FormData(emailForm);
const url = 'https://script.google.com/macros/s/AKfycbzd19Lr4aju-TLwqwLiCel6o0aLpUnOsbm2CqQTktBtavYktq6lF0l27iD7Hnqd912JOw/exec';
try {
const response = await fetch(url, {
method: 'POST',
body: formData
});
if (response.ok) {
alert('Form submitted successfully!');
emailForm.reset();
} else {
console.error('Server Error:', response.statusText);
alert('Failed to submit form.');
}
} catch (error) {
console.error('Client Error:', error);
alert('An error occurred while submitting the form.');
}
});