Created
August 26, 2011 19:28
-
-
Save maxchirkov/1174214 to your computer and use it in GitHub Desktop.
Alerts users to whilte-list your email address whenever they submit a form. Alerts could be customized to appear for only selected domain names like aol.com, earthlink.net etc.
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
//Script assumes that you have jQuery loaded. Most WordPress themes do. | |
jQuery(document).ready(function(){ | |
//Check email addresses | |
//All domains have to be be lower case | |
var check_emails = new Array("earthlink.net", "aol.com"); | |
var email_warning = "Please make sure to white-list our email address test@test.com so it doesn't get stuck in your SPAM folder."; | |
var form_selector = 'form'; //change to '#form_id' - to apply to a specific form ID. | |
jQuery(form_selector).submit(function(){ | |
jQuery('input').each(function(){ | |
//check if form field values contain @ - we assume that's email address | |
var field_value = jQuery(this).val(); | |
if( field_value.indexOf('@') != -1 ){ | |
var parts = field_value.split('@'); | |
//Get the domain part of the email | |
var check_domain = jQuery.trim( parts.splice(1,1) ).toLowerCase(); | |
//Check if emails array has values | |
if( check_emails.length > 0 ){ | |
//see if newly entered domain is in the predefined array | |
if( check_emails.indexOf(check_domain) != -1 ){ | |
alert( email_warning ); | |
} | |
}else{ | |
//If no domains defined, we assume that warning applies to all emails. | |
alert( email_warning ); | |
} | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment