APIs & Integrations

Anonymous
Not applicable

Form Email Validation - Block all providers except one

SOLVE

Hi,

 

I've created a form with 2 fields ie: Email and Name.

 

I would like to only accept submissions if the email address contains "@marc.com" and restrict all other domains (not just free providers) and display an error if the email entered is eg. @gmail.com, yahoo.com, etc

 

From what I gather, the form options only allow me to block domains and not block all and only whitelist a certain domain...

 

Any ideas or suggestions on how to implement this using onFormSubmit or any other methods?

 

Thank you in advance

 

1 Accepted solution
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

Form Email Validation - Block all providers except one

SOLVE

Hi @Anonymous ! While we can tackle this in the opposite way in the HubSpot tool, i.e. block certain domains, we don't have a way to allow only a certain domain to be submitted. For this, you'd have to use some JavaScript to check whether or not the domain name matches the one you'd like to allow. 

 

Something like this would work inside the onFormSubmit callback function on the form, or you could utilize global form events (onFormSubmit again) in order to tackle this issue. Something like this would work:

 

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
       // VALIDATE EMAIL AND SUBMIT
   }
});

Let me know if you have questions! Happy to see if I can find any alternatives if this won't work!

View solution in original post

3 Replies 3
cbarley
Solution
HubSpot Alumni
HubSpot Alumni

Form Email Validation - Block all providers except one

SOLVE

Hi @Anonymous ! While we can tackle this in the opposite way in the HubSpot tool, i.e. block certain domains, we don't have a way to allow only a certain domain to be submitted. For this, you'd have to use some JavaScript to check whether or not the domain name matches the one you'd like to allow. 

 

Something like this would work inside the onFormSubmit callback function on the form, or you could utilize global form events (onFormSubmit again) in order to tackle this issue. Something like this would work:

 

window.addEventListener('message', event => {
   if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormSubmit') {
       // VALIDATE EMAIL AND SUBMIT
   }
});

Let me know if you have questions! Happy to see if I can find any alternatives if this won't work!

geekbleek
Participant

Form Email Validation - Block all providers except one

SOLVE

This actually doesn't work - the onFormSubmit method is non-blocking as indicated here:

 

https://428357.hs-sites.com/global-form-events?__hstc=20629287.9f00fb7b5f007831e42b7371f39b04a5.1576...

 

So the form will still continue to submit, even though that event is called.  We still need a method to filter forms by domain.

0 Upvotes
Anonymous
Not applicable

Form Email Validation - Block all providers except one

SOLVE

Apologies for my late response@cbarley  but you are a legend thank you so much! 

0 Upvotes