Skip to content

Instantly share code, notes, and snippets.

@MurtzaM
Created September 9, 2014 23:49
Show Gist options
  • Save MurtzaM/3c59bb67ec2f1e052ae1 to your computer and use it in GitHub Desktop.
Save MurtzaM/3c59bb67ec2f1e052ae1 to your computer and use it in GitHub Desktop.
This script will prevent Marketo form submission if a user enters a non-business email (Gmail, Hotmail, etc.)
//This script prevents Marketo form submission if a user enters non-business email (Gmail, Hotmail, Yahoo, etc.)
//It will work on any page with a Marketo form, and runs when the form is ready
//For further info, please see Marketo form documentation, http://developers.marketo.com/documentation/websites/forms-2-0/
//Prepared by Ian Taylor and Murtza Manzur on 9/9/2014
<script>
(function (){
// Please include the email domains you would like to block in this list
var invalidDomains = ["@gmail.","@yahoo.","@hotmail.","@live.","@aol.","@outlook."];
MktoForms2.whenReady(function (form){
form.onValidate(function(){
var email = form.vals().Email;
if(email){
if(!isEmailGood(email)) {
form.submitable(false);
var emailElem = form.getFormElem().find("#Email");
form.showErrorMessage("Must be Business email.", emailElem);
}else{
form.submitable(true);
}
}
});
});
function isEmailGood(email) {
for(var i=0; i < invalidDomains.length; i++) {
var domain = invalidDomains[i];
if (email.indexOf(domain) != -1) {
return false;
}
}
return true;
}
})();
</script>
@razorfrog
Copy link

Edited submitable to submittable and added code to the footer - works great! Thank you.

@bmlyon
Copy link

bmlyon commented May 12, 2020

I know this is old but I came across it on the Marketo developers site.

Thought you might appreciate the heads-up that you've written "submitable" instead of "submittable" here form.submitable(false); (lines 16 and 20).

Thanks for the snippet!

Thank you kind sage! I was tearing my hair out trying to figure out what was wrong with a codebase I recently inherited. It looks like they copy-pasted the same mistake and never validated functionality. Kudos to you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment