I was hoping someone could provide some assistance, please.
We currently have 600+ forms and block email domains via the checkbox and also via the additional ones I add into the form field.
Our domain list constantly grows by a month to month basis and having to update these 600+ forms individually each time we have a new domain to block has become very tedious, time-consuming and soul-crushing.
Is there a better way I can go about this?
The people with these domains should not be allowed to submit the form nevermind making it onto our contact database.
From my understanding the domains are blocked at the form level and not portal level, as you said. @MFrankJohnson had a solution in this older post on how he handles this, using a workflow as a triage point.
I did work through the article earlier this morning, the one with the workflow but unfortunately, that would not be an option for us as it would still allow the domain(s) in question to submit a form and either register or potentially gain access to something.
Do you think there would be a way to make use of a HubDB table with the Domain data added to the table and then I assume using a mixture of HubL and JavaScript be able to customize it to filter those domains out and not allow the submission to go through?
Even if that means we will have to add code to the pages that contain the form, I think it will be an easier way around it then manually updating these forms.
You could create a varible that contains all the domains you with to block.
Then write a script that loops through those values on change as a vaildation process.
If it fails that validation prevent the form from being submitted, and possibly even remove the submit eventlistener.
We are actually looking at creating a repo on our site that would gate content and I'm sure we wouldn't want to just allow the competition to have it. This is a great usecase and I'd love to workwith and follow you through this case!
Thank you for the feedback, glad to hear we may have a possible solution!
It would be great to be able to work on this together, I for one do not have much knowledge in this department, so learning as we go on and taking snippets from previously set up pages and forums.
I am getting the value of the email input via javascript, then checking if that value is present in my DataBase. After that, I will write the logic to disable the button and prompt a validation message.
When I run my JS in the console, it works fine, when I publish my JS to the template, it doesn't seem to work.
So I did some digging and just completed a brief test this morning. And I think we've got a good start.
Working with code from this article, we can bypass the form action(post), run our validation, and finally trigger the form submission. This does get a 415 error meaning the server rejected the submission, but my contact list says otherwise…we'll have to dive into that later. Or maybe someone with more experience in the area can help out!
Apr 15, 20209:05 AM - edited Apr 15, 20209:23 AM
Recognized Expert | Partner
Blocked Email domains on form submission
First stab at this:
$(document).ready(function(){
const blockedDomains = ['verizon.com', 'att.net', 'hotmail.com'];
var checkExist = setInterval(function() {
if ($('form').length) {
console.log("Exists!");
clearInterval(checkExist);
var ourForm = $('form');
ourForm.on('submit', function() {
// Prevent Submission
preventDefault();
// Assign varible to email field value
var email = ourForm.find('input[type=email]').val();
// Extract the email's domain
var emailDomain = email.slice( ( email.indexOf('@') + 1 ), email.length );
// Test if the domain is in the blocked domains
var resp = $.inArray( emailDomain, blockedDomains ) ? true : false;
// Handle the response of our validation above
if (resp) {
// If resp is true
ourForm.submit();
} else {
// Else do nothing
return
}
});
}
}, 100); // check every 100ms
// Call checkExists
checkExist();
});
//Trigger function on form submit $("form").submit(function(e) {
//Getting the value from email field var emailValue = $("input[type=email]").val(); alert(emailValue); //removes name from email domain var splitArray = emailValue.split("@");
//Checks if domain is in rejectList if(rejectList.indexOf(splitArray[1]) >= 0) { alert("Incorrect email address"); //prevents form from being submitted e.preventDefault(); //add validation in here }
});
</script>
And it does not seem to work!
There is a link in the above code labeled as REF. This is what I used this morning to add the HubDB table.
I am going to spend more time on this after I finish work for the day.
Hey @CandiceLloyd I think I've got something that works!
HubDB Table:
ID
blocked_domain
12345
gmail.com
23456
aol.com
The Hubl:
<script> window.blockedDomains = [
{% for row in hubdb_table_rows(**table #**) %}
'{{row.**column_name**}}',
{% endfor %}
];
</script>
The JS:
$(document).ready(function(){
const blockedDomains = window.blockedDomains;
$('form').on('submit', function(e) {
// Assign varible to email field value
var email = $('form').find('input[type=email]').val();
// Extract the email's domain
var emailDomain = email.slice( ( email.indexOf('@') + 1 ), email.length );
// Test if the domain is in the blocked domains
($.inArray( emailDomain, blockedDomains ) > -1) ? e.preventDefault() : void(0);
});
});
Thank you so much for this! It is exciting to see that we are getting somewhere.
On testing the code on my landing page, the database information is being pulled through to the blocked domains array.
For some reason, the remainder of the script is not firing. I have console.log() the email var and it seems that this is the origin of the problem. Do you have any idea why? or what else I can try?
// Assign varible to email field value var email = $('form').find('input[type=email]').val(); // Extract the email's domain var emailDomain = email.slice( ( email.indexOf('@') + 1 ), email.length ); // Test if the domain is in the blocked domains ($.inArray( emailDomain, blockedDomains ) > -1) ? e.preventDefault() : void(0);
Apr 17, 20208:57 AM - edited Apr 17, 20208:58 AM
Recognized Expert | Partner
Blocked Email domains on form submission
Alright, so a few things:
Sorry I didn't catch this earlier .
It looks like HS handles form submissions differenctly than "native", so we've got to approach this differently.
Rather than catch the submission we'll have to prevent it all together.
The jQuery below fires a function when the email field changes. This function checks the email domain against the "blocked" list. If it is on the blocked list it disables the submit button.
$(document).ready(function(){
// Get blocked array
const blockedDomains = window.blockedDomains;
// Assign varible to email field value
var emailInput = $('form').find('input[type=email]');
emailInput.change(function(e) {
// Assign varible to email field value
var email = $('form').find('input[type=email]').val();
// Extract the email's domain
var emailDomain = email.slice( ( email.indexOf('@') + 1 ), email.length );
console.log('email changed');
if ( $.inArray( emailDomain, blockedDomains ) > -1 ) {
console.log('disabled the submit button');
$('input[type="submit"]').css({'opacity':'0.5'}).prop("disabled", true);
}
});
});
I threw in a .css({'opacity':'0.5'}) so i could see it work. You can adjust or remove this if you don't want to give the user a hint as to why they can't submit the form.
if(all_domains.includes(domain)) { console.log('Email not permitted.') // can we change the email to blank or stop the value from going through? }; } }); </script>
So still fighting with it to see what can be done!
A lot happening here, which leaves room for error. Good news I think we can simplify this quite a lot! I'll try to squeeze some time in today to go through everything.
But at a glance:
The way you're populating the blocked domain variable with Hubl doesn't look correct. It looks like you're pushing objects into the array, which doesn't need to happen.
Also if you're using an attached JS file and a custom module to get the code on the page we may want to declare the blocked domain s array as a global variable on the window object.
window.domains = [
{% for row in hubdb_table_rows(*table#*) %}
"'" ~ row.domain_column ~ "',"
{% endfor %}
];
With something like this we can access the data from anywhere on the page.