Skip to content

Instantly share code, notes, and snippets.

@TNHSAesop
Last active December 10, 2020 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TNHSAesop/210977db2408f5679f59b219d8df0436 to your computer and use it in GitHub Desktop.
Save TNHSAesop/210977db2408f5679f59b219d8df0436 to your computer and use it in GitHub Desktop.
Block Contact Form Spam By Disabling Paste
// disable copy paste into text area fields to prevent spammers from blowing up forms
jQuery(document).on('YourEventTypicallyDocumentReady', function() {
// disable keyboard paste
jQuery('YourFormFieldSelector').bind("cut copy paste", function(e) {
e.preventDefault();
});
// disable context menu to prevent right click pasting
jQuery('YourFormFieldSelector').bind("contextmenu", function(e) {
e.preventDefault();
});
});
/* Below are some semi complete examples, use with caution */
/* Catch All On Ready */
// disable copy paste into text area fields to prevent spammers from blowing up forms
jQuery(document).on('ready', function() {
// disable keyboard paste
jQuery('form textarea').bind("cut copy paste", function(e) {
e.preventDefault();
});
// disable context menu to prevent right click pasting
jQuery('form textarea').bind("contextmenu", function(e) {
e.preventDefault();
});
});
/* End Catch All OnReady */
/* Ninja Forms */
// disable copy paste into text area fields to prevent spammers from blowing up forms
jQuery(document).on('nfFormReady', function() {
// disable keyboard paste
jQuery('.nf-form-wrap textarea').bind("cut copy paste", function(e) {
e.preventDefault();
});
// disable context menu to prevent right click pasting
jQuery('.nf-form-wrap textarea').bind("contextmenu", function(e) {
e.preventDefault();
});
});
/* End Ninja Forms Example */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment