After changing the Contact Us feature to a webform, we received an increasing number of spam submissions despite implementing a honeypot and CAPTCHA. The solution is to move the contact form to a new URL and override the footer hyperlink with a JS redirect.
- Leave the Quick Links menu's "Contact Us" link as-is
- Navigate to /admin/structure/webform/manage/contact_us/settings and change the Contact Us webform URL path to /contact-the-iac
- Navigate to /admin/config/search/redirect
- Enter "contact-us" in the search box, then click Filter
- Select and delete all aliases
- Navigate to /admin/structure/block/block-content and edit the Content Info block
- Click on Source in the editor toolbar, then add the following HTML to the bottom of the block:
<div id="b64path" hidden>L2NvbnRhY3QtdGhlLWlhYw==</div>
(the L2N... string is Base64 encoding for "/contact-the-iac")
- Click on Source in the editor toolbar, then add the following HTML to the bottom of the block:
- Edit the file $D9/themes/custom/iac_theme
- Add the following line to the end of the "js:" section:
assets/js/b64path.js: {}
- Add the following line to the end of the "js:" section:
- Create a new file in $D9/themes/custom/iac_theme/assets/js/b64path.js:
$(document).ready(function () {
$("a[href='/contact-us']").click(function(event) {
window.location.href = atob($("div#b64path").html().replace(/^\s+|\s+$/g, "")), !1
event.preventDefault();
})
}) - Navigate to /admin/config/development/performance and click on the "Clear all caches" button