forked from khushi-joshi-05/Food-ordering-website
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,51 @@ | ||
|
||
const submitBtn = document.getElementById('contactForm'); | ||
|
||
submitBtn.addEventListener('submit', (event) => { | ||
event.preventDefault(); | ||
const toast = 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" // Example custom class for styling | ||
}) | ||
toast.showToast(); | ||
document.getElementById('first-name').value = ''; | ||
document.getElementById('last-name').value = ''; | ||
document.getElementById('email').value = ''; | ||
document.getElementById('message').value = ''; | ||
}); | ||
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(); | ||
} | ||
}); |