Skip to content

Commit

Permalink
Fixes issue khushi-joshi-05#1210
Browse files Browse the repository at this point in the history
  • Loading branch information
Ajita369 committed Jul 2, 2024
1 parent a24c1b3 commit d27fcaa
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions contact-form.js
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();
}
});

0 comments on commit d27fcaa

Please sign in to comment.