Last active
December 10, 2020 14:24
-
-
Save TNHSAesop/210977db2408f5679f59b219d8df0436 to your computer and use it in GitHub Desktop.
Block Contact Form Spam By Disabling Paste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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