Say Goodbye to Contact Form Spam

A simple, non disruptive strategy to reduce spam from a website’s contact form.

TL;DR

A contact form on a website

Getting messages

Spammers use the website differently

The Pareto principle

What didn’t I Do

What did I do

function enableForm() {
const form = document.querySelector("form.contact");
// This only needs to run once
if (form.getAttribute("mod") === "1") { return; }
const action = form.getAttribute("action");
const realEmail = "my@email.com";
const newAction = action.replace(
/(\?destination=)([^&]+)(&|$)/,
`$1${realEmail}$3`
);
form.setAttribute("action", newAction);
form.setAttribute("mod", "1");
}

document.addEventListener("mousemove", enableForm);
setTimeout(enableForm, 1000);

Surprisingly Good Results

--

--

I woke up like this

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store