refactor: improve contact form anti-spam handling
All checks were successful
Deploy Portfolio to VPS / deploy (push) Successful in 22s

This commit is contained in:
Chneemann 2026-07-31 08:51:33 +02:00
parent 4ed8d309ab
commit b221d2bcc1
No known key found for this signature in database

View file

@ -24,9 +24,9 @@ export default function Contact() {
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => { const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
// Anti-spam check 1: Submissions faster than 3 seconds are treated as automated bots // Anti-spam check 1: Submissions faster than 1 seconds are treated as automated bots
const timeTaken = (Date.now() - formLoadTime) / 1000; const timeTaken = (Date.now() - formLoadTime) / 1000;
if (timeTaken < 3) { if (timeTaken < 1) {
setSubmitted(true); setSubmitted(true);
return; return;
} }
@ -52,7 +52,6 @@ export default function Contact() {
name, name,
email, email,
message, message,
_replyto: email,
_subject: `Portfolio Contact: ${name}`, _subject: `Portfolio Contact: ${name}`,
}), }),
}); });
@ -158,11 +157,12 @@ export default function Contact() {
) : ( ) : (
/* Form Container */ /* Form Container */
<form onSubmit={handleSubmit} className="space-y-4"> <form onSubmit={handleSubmit} className="space-y-4">
{/* Hidden Honeypot Field for Bot Catching */} {/* Visual Hidden Honeypot Field */}
<div className="hidden" aria-hidden="true"> <div
<label className="block text-xs mb-1.5" htmlFor="website_hp"> className="absolute opacity-0 pointer-events-none -z-10 h-0 w-0 overflow-hidden"
Website aria-hidden="true"
</label> >
<label htmlFor="website_hp">Website</label>
<input <input
type="text" type="text"
id="website_hp" id="website_hp"