refactor: improve contact form anti-spam handling
All checks were successful
Deploy Portfolio to VPS / deploy (push) Successful in 22s
All checks were successful
Deploy Portfolio to VPS / deploy (push) Successful in 22s
This commit is contained in:
parent
4ed8d309ab
commit
b221d2bcc1
1 changed files with 8 additions and 8 deletions
|
|
@ -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"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue