SOLVED

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Go to solution
SanfordWhiteman
Level 10 - Community Moderator

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Hi Justin,

 

1st: Even though you're loading the FormsPlus::EmailPattern JS library, I don't see that you're using it. It's just available for use.

 

2nd: The call to the external enforcement service (wouldn't call it a webhook, as it's an API called from the browser) needs to be interlocked with the FormsPlus.EmailPattern.match method. It doesn't make sense to call enforcement if the form isn't ready to be posted at all because the email is from an unwanted domain. So the match should run first; then if there's no match, you call enforcement; then when the enforcement API returns, you submit the form.

laberge
Level 1

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Thanks for the clarity here Sandy, I'll make some changes to where the code is stored and how it's getting loaded.

albert2982001
Level 2

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Where would I add this code to a Marketo landing page template where the form is hidden or enabled?

SanfordWhiteman
Level 10 - Community Moderator

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

On a Marketo LP, custom form behaviors JS should go just before the closing </body> tag. This is because you don't know exactly where in the body the Forms 2.0 lib will be injected, so you have to make sure you're after that.

albert2982001
Level 2

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Thanks for the quick reply. Here's a link to my marketo landing page in question, https://info.leandata.com/G2_L2AReport.html

 

I entered <!-- FormsPlus libraries -->
<script id="teknklFormsPlus-EmailPattern-1.0.3" src="https://info.leandata.com/rs/554-VZA-399/images/formsplus-emailpattern-1.0.3.js"></script>
<!-- /FormsPlus libraries --> right before the /body however it still doesn't appear to be working. 

 

Page Source: view-source:https://info.leandata.com/G2_L2AReport.html

SanfordWhiteman
Level 10 - Community Moderator

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

You seem to have miscopied the FormsPlus::EmailPattern JS file before reuploading it to your server. Maybe you pasted it into Word or something? You need to download the actual file in its original form.

SanfordWhiteman_0-1638244854524.png

 

albert2982001
Level 2

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Here's the test website I setup with I believe is the correct js code this time around. However, the script now blocks any form submission and does not display the error message. 

https://info.leandata.com/Testing---Email-Validation_test.html

SanfordWhiteman
Level 10 - Community Moderator

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

You still have the wrong script. Looks like you saved the contents of the JS pane as a .JS file. You need the stuff in the JS pane, but that’s not the same as the FormsPlus::EmailPattern file, which is a separate file (and also directly linked above).
plane
Level 2

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

Thanks for this clever script @SanfordWhiteman! I'm trying to implement it alongside your validation of a string field for websites (from this post) but it looks like the form can be submitted if one of the two (email or website) is correct. Is there a way I can roll these two together into one custom validator script? 

 

Thanks for all your help!!

SanfordWhiteman
Level 10 - Community Moderator

Re: How to Restrict Free Email Domains on Form Fill Out in 2021

I edited both samples so they will persist the submittable state properly (i.e. if one sets it to false, the other will persist that value and stop the form from submitting). Should probably work this little method into a blog post.