Skip to content

Instantly share code, notes, and snippets.

@azl397985856
Created March 27, 2020 05:34
Show Gist options
  • Save azl397985856/3fd19b78a1f33531035fe45872729f8b to your computer and use it in GitHub Desktop.
Save azl397985856/3fd19b78a1f33531035fe45872729f8b to your computer and use it in GitHub Desktop.
Defeating Form Spam Bots
<form id='myContactForm' action='https://cohan.me/that-needs-js/'
      data-action='https://cohan.me/your/actual/form/submit/url'>

<script>
    function updateContactFormDestination() {
        var contactForm = document.getElementById("myContactForm");
        var realSubmitUrl = contactForm.getAttribute('data-action');

        contactForm.setAttribute('action', realSubmitUrl);
    }

    document.addEventListener("DOMContentLoaded", function(event) { 
        updateContactFormDestination();
    });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment