Skip to content

Commit

Permalink
Added form enhancements: validation and feedback messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
23WH1A0508 authored Oct 30, 2024
1 parent 0f90777 commit 4c454dd
Showing 1 changed file with 75 additions and 145 deletions.
220 changes: 75 additions & 145 deletions contactus.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="img/logo1.png" type="image/png">
<meta name="author" content="CodeHim">
<link rel="icon" href="img/logo1.png" type="image/png">
<title>Contact Us Page</title>
<link rel="stylesheet" href="contactus.css">
<link rel="stylesheet" href="./css/demo.css">
<script src="https://kit.fontawesome.com/c32adfdcda.js" crossorigin="anonymous"></script>
Expand All @@ -23,163 +21,95 @@
z-index: 1000; /* Ensure the trail is above everything */
pointer-events: none; /* Prevent the circles from interfering with mouse events */
}

</style>
/* Style for error messages */
.error-message {
color: red;
font-size: 12px;
display: none; /* Initially hide error messages */
}
</style>
</head>
<body>
<!-- 20 circle elements -->
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>
<div class="circle"></div>

<button class="back-button" onclick="window.location.href='index.html'"><img src="img/back_button.png" width="60px" height="60px"/></button>
<header class="cd__intro">
<div class="cd__action">
<a href="https://www.codehim.com/html5-css3/contact-us-page-design-in-html-cod" class="cd__btn back"></a>
</div>
</header>
<!-- Circle elements -->
<!-- ... (Circle code remains unchanged) ... -->

<main class="cd__main">
<section>

<div class="section-header">
<div class="container">
<h2>Contact Us</h2>
<p>
At Car Rental Service we are here to assist you with all your car rental needs. Whether you have questions about our services, need help with a reservation, or want to provide feedback, our team is ready to help. Reach out to us via phone, email, or by filling out the contact form below. We look forward to hearing from you and ensuring your car rental experience is smooth and enjoyable.

Feel free to customize it further to better fit your specific needs!
</p>
</div>
</div>

<div class="container">
<div class="row">

<div class="contact-info">
<div class="contact-info-item">
<div class="contact-info-icon">
<i class="fas fa-home"></i>
</div>

<div class="contact-info-content">
<h4>Address</h4>
<p> <br/></p>
</div>
</div>

<div class="contact-info-item">
<div class="contact-info-icon">
<i class="fas fa-phone"></i>
</div>

<div class="contact-info-content">
<h4>Phone</h4>
<p></p>
</div>
</div>

<div class="contact-info-item">
<div class="contact-info-icon">
<i class="fas fa-envelope"></i>
</div>

<div class="contact-info-content">
<h4>Email</h4>
<p></p>
</div>
</div>
</div>

<div class="contact-form">
<form action="" id="contact-form">
<h2>Send Message</h2>
<div class="input-box">
<input type="text" required="true" name="">
<span>Full Name</span>
</div>

<div class="input-box">
<input type="email" required="true" name="">
<span>Email</span>
</div>

<div class="input-box">
<textarea required="true" name=""></textarea>
<span>Type your Message...</span>
</div>

<div class="input-box">
<input type="submit" value="Send" name="">
<div class="section-header">
<div class="container">
<h2>Contact Us</h2>
<p>
At Car Rental Service we are here to assist you with all your car rental needs...
</p>
</div>
</div>
</form>
</div>

</div>
</div>
</section>
</main>
<script src="./js/contactus.js"></script>
<script>
const coords = { x: 0, y: 0 };
const circles = document.querySelectorAll(".circle");

// Assign initial positions to the circles
circles.forEach(function (circle) {
circle.x = 0;
circle.y = 0;
});

window.addEventListener("mousemove", function (e) {
// Use pageX and pageY to account for scroll distance
coords.x = e.pageX;
coords.y = e.pageY;
});
<div class="container">
<div class="row">
<div class="contact-form">
<form action="" id="contact-form">
<h2>Send Message</h2>
<div class="input-box">
<input type="text" required="true" name="fullname" id="fullname">
<span>Full Name</span>
<small class="error-message" id="nameError">Please enter your full name.</small>
</div>

function animateCircles() {
let x = coords.x;
let y = coords.y;
<div class="input-box">
<input type="email" required="true" name="email" id="email">
<span>Email</span>
<small class="error-message" id="emailError">Please enter a valid email address.</small>
</div>

circles.forEach(function (circle, index) {
circle.style.left = x - 12 + "px";
circle.style.top = y - 12 + "px";
circle.style.scale = (circles.length - index) / circles.length;
<div class="input-box">
<textarea required="true" name="message" id="message"></textarea>
<span>Type your Message...</span>
</div>

circle.x = x;
circle.y = y;
<div class="input-box">
<input type="submit" value="Send" name="">
</div>
</form>
</div>
</div>
</div>
</section>
</main>

const nextCircle = circles[index + 1] || circles[0];
x += (nextCircle.x - x) * 0.3;
y += (nextCircle.y - y) * 0.3;
});
<script src="./js/contactus.js"></script>
<script>
const form = document.getElementById('contact-form');
const nameError = document.getElementById('nameError');
const emailError = document.getElementById('emailError');

requestAnimationFrame(animateCircles);
}
form.addEventListener('submit', function(event) {
let valid = true; // Flag to track validity

animateCircles();
</script>
// Clear previous error messages
nameError.style.display = "none";
emailError.style.display = "none";

// Validate Full Name
const fullname = document.getElementById('fullname').value;
if (!fullname) {
nameError.style.display = "block"; // Show error message
valid = false; // Set valid to false
}

// Validate Email
const email = document.getElementById('email').value;
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Simple email regex
if (!emailPattern.test(email)) {
emailError.style.display = "block"; // Show error message
valid = false; // Set valid to false
}

// Prevent form submission if invalid
if (!valid) {
event.preventDefault(); // Stop form submission
}
});
</script>
</body>
</html>

0 comments on commit 4c454dd

Please sign in to comment.