mirror of
https://github.com/its-michaelroy/Simple_Portfolio.git
synced 2026-06-03 23:00:43 +00:00
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:
42
assets/js/formHandler.js
Normal file
42
assets/js/formHandler.js
Normal 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";
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user