feat: Add Privacy Policy acceptance to contact form and client-side validation to contact-form.js

This commit is contained in:
2025-08-25 23:04:57 -05:00
parent 04da9dde0b
commit 5cf47eb202
5 changed files with 60 additions and 14 deletions

View File

@@ -52,11 +52,9 @@ form.addEventListener("submit", function(event) {
const honeypotField = document.getElementById("url").value.trim();
if (honeypotField.length > 0) {
console.warn("Honeypot field was filled. Blocking submission.");
// Fail silently to avoid alerting the bot.
return;
}
// Get values, including the hCaptcha response token
const firstName = document.getElementById("first-name").value.trim();
const lastName = document.getElementById("last-name").value.trim();
const organization = document.getElementById("organization").value.trim();
@@ -64,7 +62,8 @@ form.addEventListener("submit", function(event) {
const phone = document.getElementById("phone").value.trim();
const contactMethod = document.querySelector('input[name="contact-method"]:checked')?.value;
const message = document.getElementById("message").value.trim();
// Get the hCaptcha token from the global hcaptcha object
const privacyAccepted = document.getElementById("privacy").checked;
let hasErrors = false;
// Validation logic...
@@ -114,6 +113,11 @@ form.addEventListener("submit", function(event) {
hasErrors = true;
}
if (!privacyAccepted) {
showMessage("Privacy Policy must be accepted before submitting.", true);
hasErrors = true;
}
if (!hasErrors) {
// Package the form data, including the hCaptcha token
@@ -126,7 +130,8 @@ form.addEventListener("submit", function(event) {
contactMethod: contactMethod,
message: message,
url: honeypotField,
hCaptchaResponse: hCaptchaResponse // <-- THIS IS THE NEW PART
hCaptchaResponse: hCaptchaResponse,
privacyAccepted: privacyAccepted
};
// Send the data to the backend using fetch()