Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.