-
Notifications
You must be signed in to change notification settings - Fork 780
/
contact.js
56 lines (48 loc) · 1.39 KB
/
contact.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
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
// Sending Data to Mail
// Listenig to form
const contactForm = document.querySelector(".contact__form");
async function handleFormSubmit(event) {
event.preventDefault();
const subject = document.querySelector(".subject");
const msgStatus = document.querySelector(".msg__status");
subject.value = "Msg via Naruto Webpage";
const form = event.currentTarget;
const url = form.action;
try {
const formData = new FormData(form);
const fetchOptions = {
method: contactForm.method,
headers: {
Accept: "application/json",
},
body: formData,
};
await fetch(url, fetchOptions);
console.log(url);
if (url=="https://formsubmit.co/[email protected]"){
await Swal.fire({
title: "Success!",
text: "Message Sent Successfully!",
icon: "success"
});
}
else{
await Swal.fire({
icon: "error",
title: "Oops...",
text: "Something went wrong!"
});
}
form.reset();
} catch (err) {
msgStatus.innerHTML =
"Oops! There was a problem delivering your message, please contact via other means.";
msgStatus.style.display = "block";
msgStatus.style.textAlign = "center";
setTimeout(() => {
msgStatus.style.display = "none";
}, 4000);
form.reset();
}
}
contactForm.addEventListener("submit", handleFormSubmit);