Skip to content

Commit

Permalink
Merge pull request #1244 from Lokesh-Bijarniya/main
Browse files Browse the repository at this point in the history
Add Validation to Feedback and Contact Forms to Prevent Invalid Data Submission
  • Loading branch information
ANSHIKA-26 authored Oct 20, 2024
2 parents 1c2bcd5 + 58bc881 commit ca432bd
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 176 deletions.
17 changes: 8 additions & 9 deletions contact_us.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
document.addEventListener("DOMContentLoaded", () => {
const sendEmailButton = document.getElementById("sendEmailButton"); // Assuming your button has this ID
const sendEmailButton = document.getElementById("sendEmailButton");

sendEmailButton.addEventListener("click", SendEmail);
});

async function SendEmail(event) {
event.preventDefault();

const firstName = document.getElementById("firstName").value.trim();
const lastName = document.getElementById("lastName").value.trim();
const email = document.getElementById("email").value.trim();
const Name = document.getElementById("Name").value.trim(); // Corrected ID
const email = document.getElementById("email2").value.trim(); // Corrected ID
const phone = document.getElementById("phone").value.trim();
const message = document.getElementById("message").value.trim();

// Input validation
if (!firstName || !lastName || !email || !phone || !message) {
if (!Name || !email || !phone || !message) {
alert("All fields are required.");
return;
}
Expand All @@ -24,13 +23,13 @@ async function SendEmail(event) {
return;
}

console.log(Name,email,phone,message);
console.log(Name, email, phone, message); // Corrected variable name

if (message.length < 10) {
alert("Message must be at least 10 characters long.");
return;
}
//console.log("Email value:", email , Name, phone, message);

const data = {
Name: Name,
email: email,
Expand All @@ -46,7 +45,7 @@ async function SendEmail(event) {
});

const result = await response.json();

if (response.ok) {
showPopup();
document.getElementById("contactForm").reset();
Expand Down Expand Up @@ -89,4 +88,4 @@ function hidePopup() {

function handleErrorResponse(result) {
alert(`Error: ${result.message || 'An unexpected error occurred.'}`);
}
}
Loading

1 comment on commit ca432bd

@vercel
Copy link

@vercel vercel bot commented on ca432bd Oct 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.