-
Notifications
You must be signed in to change notification settings - Fork 433
/
contact-form.js
51 lines (47 loc) · 1.88 KB
/
contact-form.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
const submitBtn = document.getElementById('contactForm');
submitBtn.addEventListener('submit', (event) => {
event.preventDefault();
const firstName = document.getElementById('first-name').value;
const lastName = document.getElementById('last-name').value;
const email = document.getElementById('email').value;
const message = document.getElementById('message').value;
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (firstName && lastName && email && message) {
if (emailPattern.test(email)) {
Toastify({
text: "Your message has been sent successfully!",
duration: 3000,
style: {
background: "linear-gradient(to top, #e37f0f, #df8d0a, #db9b0c, #d5a816, #cfb423)",
borderRadius: "25px"
},
gravity: "bottom"
}).showToast();
// Reset the form fields
document.getElementById('first-name').value = '';
document.getElementById('last-name').value = '';
document.getElementById('email').value = '';
document.getElementById('message').value = '';
} else {
Toastify({
text: "Please enter a valid email address.",
duration: 3000,
style: {
background: "linear-gradient(to top, #ff0000, #ff4d4d, #ff6666, #ff8080, #ff9999)",
borderRadius: "25px"
},
gravity: "bottom"
}).showToast();
}
} else {
Toastify({
text: "Please fill in all fields.",
duration: 3000,
style: {
background: "linear-gradient(to top, #ff0000, #ff4d4d, #ff6666, #ff8080, #ff9999)",
borderRadius: "25px"
},
gravity: "bottom"
}).showToast();
}
});