Added capcha, functionality for senidng emails, and refactored code for the images to go to LiveCode/url and Github code if unavailable

This commit is contained in:
its-michaelroy
2024-07-25 17:33:45 -03:00
parent 2942ced2db
commit b27dc4978f
6 changed files with 3156 additions and 3233 deletions

42
assets/js/formHandler.js Normal file
View File

@@ -0,0 +1,42 @@
let hcaptchaVerified = false;
// Callback function for hCaptcha
function onVerify() {
hcaptchaVerified = true;
}
// Prevent form submission if hCaptcha is not verified
document.getElementById("contactForm").addEventListener("submit", function (e) {
e.preventDefault(); // Prevent the default form submission
if (hcaptchaVerified) {
const email = document.getElementById("email").value;
document.getElementById("subject").value = `New submission from ${email}`;
// Use fetch to submit the form data
fetch(this.action, {
method: "POST",
body: new FormData(this),
})
.then((response) => {
if (response.ok) {
clearFormFields(); // Clear fields on successful submission
alert("Your message has been sent!");
} else {
alert("There was a problem with your submission.");
}
})
.catch((error) => {
console.error("Error:", error);
alert("There was a problem with your submission.");
});
} else {
alert("Please complete the hCaptcha challenge."); // Alert if hCaptcha is not verified
}
});
// Function to clear form fields
function clearFormFields() {
document.getElementById("name").value = "Name";
document.getElementById("email").value = "Email";
document.getElementById("message").value = "Message";
}

View File

@@ -87,22 +87,22 @@
// Main Sections: Two.
// Lightbox gallery.
$window.on("load", function () {
$("#two").poptrox({
caption: function ($a) {
return $a.next("h3").text();
},
overlayColor: "#2c2c2c",
overlayOpacity: 0.85,
popupCloserText: "",
popupLoaderText: "",
selector: ".work-item a.image",
usePopupCaption: true,
usePopupDefaultStyling: false,
usePopupEasyClose: false,
usePopupNav: true,
windowMargin: breakpoints.active("<=small") ? 0 : 50,
});
});
// // Lightbox gallery.
// $window.on("load", function () {
// $("#two").poptrox({
// caption: function ($a) {
// return $a.next("h3").text();
// },
// overlayColor: "#2c2c2c",
// overlayOpacity: 0.85,
// popupCloserText: "",
// popupLoaderText: "",
// selector: ".work-item a.image",
// usePopupCaption: true,
// usePopupDefaultStyling: false,
// usePopupEasyClose: false,
// usePopupNav: true,
// windowMargin: breakpoints.active("<=small") ? 0 : 50,
// });
// });
})(jQuery);