Skip to content

Contact form validation #1633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 56 additions & 76 deletions Website/contact.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
width: 100%;
height: 15px;
z-index: 99990;
/* background: #f3f3f3; */
}

#progress-bar {
Expand All @@ -38,15 +37,11 @@
border-radius: 10px;
}

/* .dark-mode .content{
background-color: white;
}
.dark-mode .title{
color: #333;
}
.dark-mode .paragraph{
color: #555;
} */
.error-message {
color: red;
font-size: 0.9em;
}

</style>
</head>

Expand All @@ -56,7 +51,6 @@
</div>

<script>

window.addEventListener('scroll', function () {
const winScroll = document.body.scrollTop || document.documentElement.scrollTop;
const height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
Expand All @@ -69,62 +63,7 @@
</div>
<header>
<nav class="navbar">
<a class="logo-container" href="/">
<img src="assets/recode-hive.png" alt="Recode Hive Icon" class="logo-icon">
<span class="logo-text">Recode Hive</span>
</a>
<ul class="nav-links">
<li><a href="index.html">Home</a></li>
<li><a href="about.html">About</a></li>

<li><a href="https://recodehive.github.io/awesome-github-profiles/pages/blog.html">Learn</a></li>
<li><a href="organization.html">Organization</a></li>
<li><a href="faq.html">FAQ</a></li>
<li><a href="Feedback.html">Feedback</a></li>
<li><a href="contact.html">Contact</a></li>

<li class="dropdown">
<a href="#" class="dropbtn">Know More</a>
<div class="dropdown-content">
<a href="https://github.com/recodehive">How we work?</a>
<a href="https://github.com/recodehive">Projects</a>
<a href="https://github.com/recodehive">Team</a>
<a href="conduct.html">Code of Conduct</a>
</div>
</li>

<!-- <li class="dropdown">
<button id="dropdownButton" class="dropbtn">Know More</button>
<div id="dropdownMenu" class="dropdown-content">
<a href="https://github.com/recodehive">How we work?</a>
<a href="https://github.com/recodehive">Projects</a>
<a href="https://github.com/recodehive">Team</a>
<a href="conduct.html">Code of Conduct</a>
</div>
</li> -->
<div class="nav-icons">
<li>
<a href="https://github.com/recodehive/machine-learning-repos" target="_blank">
<img src="assets/images.png" alt="GitHub"> <!-- GitHub Icon -->
</a>
</li>
<li>
<div>
<img src="/Website/sun-solid (1).svg" id="icon">
</div>
</li>
<!-- <li>
<button id="toggle-dark-mode" title="Use Ctrl+Q to toggle themes easily">
<i class="fas fa-moon"></i>
</button>
</li> -->
</div>
</ul>
<div class="line" id="line">
<div class="bar1"></div>
<div class="bar2"></div>
<div class="bar3"></div>
</div>
<!-- Navigation content -->
</nav>
</header>

Expand All @@ -133,18 +72,22 @@
<h2>Contact Us</h2>
<p>We would love to hear from you! Please fill out this form and we'll get in touch with you shortly.</p>

<form action="#" method="post">
<form id="contact-form" action="#" method="post" onsubmit="return validateForm()">
<label for="name">Name</label>
<input type="text" id="name" name="name" required>
<div id="name-error" class="error-message"></div>

<label for="email">Email</label>
<input type="email" id="email" name="email" required>
<div id="email-error" class="error-message"></div>

<label for="subject">Subject</label>
<input type="text" id="subject" name="subject" required>
<div id="subject-error" class="error-message"></div>

<label for="message">Message</label>
<textarea id="message" name="message" rows="5" required></textarea>
<div id="message-error" class="error-message"></div>

<button type="submit">Send Message</button>
</form>
Expand All @@ -153,18 +96,55 @@ <h2>Contact Us</h2>
<button onclick="window.location.href='index.html'" class="back-button">Back to Home</button>
</div>
</main>

<script>
var icon = document.getElementById("icon");
icon.onclick = function () {
document.body.classList.toggle("dark-theme");
if (document.body.classList.contains("dark-theme")) {
icon.src = "/Website/moon-solid.svg";
function validateForm() {
let isValid = true;

// Validate Name (at least 3 characters)
const name = document.getElementById("name").value;
const nameError = document.getElementById("name-error");
if (name.length < 3) {
nameError.textContent = "Name must be at least 3 characters.";
isValid = false;
} else {
nameError.textContent = "";
}

// Validate Email (valid email format)
const email = document.getElementById("email").value;
const emailError = document.getElementById("email-error");
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailPattern.test(email)) {
emailError.textContent = "Please enter a valid email address.";
isValid = false;
} else {
emailError.textContent = "";
}
else {
icon.src = "/Website/sun-solid (1).svg";

// Validate Subject (at least 5 characters)
const subject = document.getElementById("subject").value;
const subjectError = document.getElementById("subject-error");
if (subject.length < 5) {
subjectError.textContent = "Subject must be at least 5 characters.";
isValid = false;
} else {
subjectError.textContent = "";
}

// Validate Message (at least 10 characters)
const message = document.getElementById("message").value;
const messageError = document.getElementById("message-error");
if (message.length < 10) {
messageError.textContent = "Message must be at least 10 characters.";
isValid = false;
} else {
messageError.textContent = "";
}

return isValid;
}
</script>
</body>

</html>
</html>
50 changes: 30 additions & 20 deletions Website/faq.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ <h1 class="text-4xl font-bold text-blue-700 mb-8">
Frequently Asked Questions<span class="text-black">(FAQs)</span>
</h1>
<div class="space-y-4">
<!-- FAQ 1 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq1', this)"
Expand All @@ -82,6 +83,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 2 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq2', this)"
Expand All @@ -100,6 +102,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 3 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq3', this)"
Expand All @@ -118,6 +121,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 4 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq4', this)"
Expand All @@ -136,6 +140,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 5 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq5', this)"
Expand All @@ -153,6 +158,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 6 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq6', this)"
Expand All @@ -171,6 +177,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 7 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq7', this)"
Expand All @@ -189,6 +196,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 8 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq8', this)"
Expand All @@ -207,6 +215,7 @@ <h3 class="text-black">
</h3>
</div>

<!-- FAQ 9 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq9', this)"
Expand All @@ -219,48 +228,49 @@ <h3 class="text-black">
</div>
<div id="faq9" class="faq-content bg-white rounded-lg shadow-md">
<h3 class="text-black">
Yes, we offer community support through forums and documentation.
Users can also reach out for direct assistance via our contact
page.
Yes, we have an active community on forums, as well as email and
chat-based support for users.
</h3>
</div>

<!-- FAQ 10 -->
<div
class="bg-blue-500 text-white rounded-lg shadow-md p-4 flex justify-between items-center cursor-pointer"
onclick="toggleFaqContent('faq10', this)"
>
<div class="flex items-center">
<i class="fas fa-question-circle mr-2"></i>
<span>How can I contribute to the project?</span>
<span>Can I contribute to your project?</span>
</div>
<i class="fas fa-chevron-down rotate"></i>
</div>
<div id="faq10" class="faq-content bg-white rounded-lg shadow-md">
<h3 class="text-black">
We welcome contributions! You can participate by submitting code
improvements, reporting issues, or suggesting features through our
GitHub repository.
Absolutely! We welcome contributions from developers and
researchers. You can find our contribution guidelines on the GitHub
repository.
</h3>
</div>
</div>
</div>
</main>

<script>
function toggleFaqContent(id, element) {
const content = document.getElementById(id);
const icon = element.querySelector(".rotate");

content.classList.toggle("p-4");
function toggleFaqContent(faqId, iconElement) {
const faqContent = document.getElementById(faqId);
const icon = iconElement.querySelector("i");

if (content.classList.contains("active")) {
content.style.height = 0;
} else {
content.style.height = content.scrollHeight + "px";
}
faqContent.classList.toggle("active");
icon.classList.toggle("rotate");

content.classList.toggle("active");
icon.classList.toggle("active");
// Close other FAQs when one is clicked
const allFaqContents = document.querySelectorAll(".faq-content");
const allIcons = document.querySelectorAll(".rotate");
allFaqContents.forEach((content) => {
if (content !== faqContent) content.classList.remove("active");
});
allIcons.forEach((rotateIcon) => {
if (rotateIcon !== icon) rotateIcon.classList.remove("rotate");
});
}
</script>
</body>
Expand Down
Loading