-
-
Save MurtzaM/3c59bb67ec2f1e052ae1 to your computer and use it in GitHub Desktop.
//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> |
Hmm.... I get "Assertion failed" errors when simply adding this script to the footer. Do I need to add this as part of the MktoForms2 tag, i.e. to MktoForms2.loadForm("//app-sjqe.marketo.com", "718-GIV-198", 621, function(form) { //add here?? });
Edited submitable to submittable and added code to the footer - works great! Thank you.
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!
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!