SOLVED

Prevent form submits from generic email domains

Go to solution
Highlighted
Anonymous
Not applicable

Prevent form submits from generic email domains

Would like to block people from using a generic email to submit a form. We're blocking them on the back end by removing them from flows but would like to show an error message or something to try to get people to use their business addresses instead. Any way to do that?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Prevent form submits from generic email domains

Hi Andrew,

This is quite well documented in the community.

Start here: http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/

-Greg

View solution in original post

8 REPLIES 8
Highlighted

Re: Prevent form submits from generic email domains

Hi Andrew,

This is quite well documented in the community.

Start here: http://developers.marketo.com/blog/restrict-free-email-domains-on-form-fill-out/

-Greg

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Prevent form submits from generic email domains

Hi Greg, what if I need one form on a page to block invalid email addresses but the other not to - we have a download form we want to block and a contact us form we do not want to block. Is that possible?

Also, do you know if the script will work if implemented through Google Tag Manager? Our script doesn't seem to be working.

Thanks!

-Andrew

Highlighted
Level 10 - Community Moderator

Re: Prevent form submits from generic email domains

Hi Andrew​,

Better to open a new thread in future (a thread tagged Correct can't have additional correct answers, plus you can't tag it if you're not the owner).

what if I need one form on a page to block invalid email addresses but the other not to - we have a download form we want to block and a contact us form we do not want to block. Is that possible?

Sure, perfectly possible.  By default, most Forms 2.0 custom behaviors attach to all forms on the current page, both because it's easier to write examples that way and because it's usually what you want. But you can easily reserve behaviors for a subset of forms (this also makes it easier to include the same JS on every single page, since it will auto-adjust depending on what form has been embedded).

MktoForms2.whenReady(function(form) {

// we will get here for every form, but...

if( [123,456].indexOf(form.getId() >= 0 ) {

   // ... this code will only run for form IDs 123 and 456

   form.onValidate(function(valid) {

     // extended validation, etc...

   });

});

});

Also, do you know if the script will work if implemented through Google Tag Manager? Our script doesn't seem to be working.Andrew

Injecting scripts asynchronously (which is what you're doing by using GTM) works as long you maintain the load order of dependent scripts.

So forms behaviors JS (making use of MktoForms2.someEvent) loaded via GTM must load after the core forms2.min.js library has completely loaded, because MktoForms2 won't exist until it's created by the library.  If forms2.min.js and your behaviors JS load independently and asynchronously, they can finish in either order, so some % of the time the code is guaranteed to fail.

Although it can be made to work perfectly, managing dependencies can be difficult if you don't have command of all the tech involved. So it may be better for you to eschew GTM here. I was debugging something exactly like this at a client today (hi guys! ).

Highlighted
Level 10 - Community Moderator

Re: Prevent form submits from generic email domains

Also, one more thing: that script is broken. It will say that promising.lead@live.corporate.com and yournextcustomer@outlook.multinational.com are free email addresses, because it erroneously does pattern matching only on the partial domain ("@live." or "@outlook."). There's no need to for it to be open-ended as free email providers don't actually give out addresses at every TLD. If you look at this post and the links in it you'll see a more scalable and accurate approach.

Highlighted
Anonymous
Not applicable

Re: Prevent form submits from generic email domains

Thanks a ton Sanford Whiteman 2 (FigureOne)​ this is incredibly helpful!

Highlighted
Level 2

Re: Prevent form submits from generic email domains

Does anyone know if there is a way to apply this code site wide? I tried applying it through my wordpress theme but the forms still go through with a personal email address.

Highlighted
Level 10 - Community Moderator

Re: Prevent form submits from generic email domains

You must make sure it loads after the Forms 2.0 library itself (forms2.min.js) as it depends on the main MktoForms2 object. Chances are you injected it in the wrong place, so it errors out. Looking in your F12 Console for that error is the first step.

Highlighted

Re: Prevent form submits from generic email domains

Hi again Andreww,

You can also use a paid (and far more advanced) service such as Etumos Verify - Etumos

-Greg