I’ve only implemented the submit button locking code (not the form hiding part) from frjo’s suggestion, and that is working great already:
// Unlock the submit button if mouse is moved (desktop)
window.addEventListener('mousemove', function () {
document.getElementById("submitBtn").disabled = false;
});
// Unlock the submit button if touchscreen is dragged (mobile)
window.addEventListener('touchmove', function () {
document.getElementById("submitBtn").disabled = false;
});
// Unlock the submit button if tab or enter is pressed (keyboard)
window.addEventListener('keydown', function (e) {
if ((e.key === "Enter") || (e.key === "Tab")) {
document.getElementById("submitBtn").disabled = false;
// console.log(e.key);
}
});
Some (but very little) spam gets through. What has worked great for the remaining spam, is cycling through the POST values before sending them, and do a simple check for a URL in any fields that shouldn’t naturally contain any (since most spam wants you to click on a URL, which will only show up as a blue link if it contains http:// or https://):
// for spam, check if string contains a URL
function containsUrl (content) {
return (/(https?:?\/\/)/.test(content));
}
That simple check has worked great also. Obviously proceed with caution and only apply to fields that really would not contain URLs naturally. Thanks again frjo!
This is very impressive! After looking for tens of ways to fight SPAM for static forms, this does it! Haven’t had any SPAM in a week! Have you documented it anywhere?
I switched to this and testing it to send email works. Will monitor spam and see. @frjo not sure why it happens, but combining this JS using Hugo’s slice makes the search form disappear.
Ignore. It was a Hugo issue. Restarting the server sold it.