SOLVED

Blocking Spam & Personal Domains Issue

Go to solution
jinawatson
Level 2

Blocking Spam & Personal Domains Issue

Hi! I'm trying to us @SanfordWhiteman's script to block personal and spam domains but for some reason when I add the script to my Marketo landing page HTML, it just redirects back to the page once clicking submit versus giving the "Must be business email" validation rule.

 

Here's the landing page: https://it.recastsoftware.com/automatedpatching.html

 

I did remove the script as the page is live and I couldn't get the redirect to stop but this is what code I dropped in before the </body> tag.

 

<!-- FormsPlus libraries -->
<script id="teknklFormsPlus-EmailPattern-1.0.3" src="https://it.recastsoftware.com/rs/563-ODB-688/images/teknkl-formsplus-emailpattern-1.0.3.js?version=0"></script>
<!-- /FormsPlus libraries -->

 

And here's the modified JS:

/*
 * @author Sanford Whiteman
 * @version v1.1 2020-11-15
 * @copyright © 2020 Sanford Whiteman
 * @license Hippocratic 2.1: This license must appear with all reproductions of this software.
 *
 *
 *
 */

(function () {
   const invalidDomains = [
      "gmail.com", 
      "yahoo.com", 
      "hotmail.com",
      "sandy@fig1.com",
      "jourrapide.com",
      "teleworm.us",
      "armyspy.com",
      "rhyta.com",
      "cuvox.de",
      "dayrep.com",
      "einrot.com",
      "fleckens.hu",
      "gustr.com",
      "superrito.com",
      "sandy@fig1.net"
      ]
      invalidMessage = "Must be a Business email.";

   const interestingEmailField = "Email";

   /* NO NEED TO ALTER BELOW THIS LINE */

   MktoForms2.whenReady(function (mktoForm) {
      const formEl = mktoForm.getFormElem()[0],
         emailEl = formEl.querySelector("[name='" + interestingEmailField + "']");

      mktoForm.onValidate(extendedEmailValidation);

      function extendedEmailValidation(nativeValid) {
         if (nativeValid === false) return;

         let currentValues = mktoForm.getValues(),
            originalSubmittable = mktoForm.submittable(),
            email = currentValues[interestingEmailField];

         if (email) {
            if (FormsPlus.emailPattern.match(email, invalidDomains)) {
               console.log("Email matches pattern, forcing submittable(false)");
               emailEl.classList.add("customInvalid");
               emailEl.setAttribute("aria-invalid", "true");
               mktoForm.submittable(false);
               mktoForm.showErrorMessage(invalidMessage, MktoForms2.$(emailEl));
            } else {
               console.log("Email does not match pattern, continuing");
               emailEl.classList.remove("customInvalid");
               emailEl.setAttribute("aria-invalid", "false");
               mktoForm.submittable(originalSubmittable);
            }
         }
      }
   });
   
})();

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Blocking Spam & Personal Domains Issue

Nope, you have a file with that name, but it has the wrong content.

View solution in original post

Jo_Pitts1
Level 10 - Community Advisor

Re: Blocking Spam & Personal Domains Issue

@jinawatson,

if I'm reading things correctly, inside <script> and </script> tags on the page with the form.

Cheers

Jo 

View solution in original post

10 REPLIES 10
SanfordWhiteman
Level 10 - Community Moderator

Re: Blocking Spam & Personal Domains Issue

You need to download the actual FormsPlus::EmailPattern library and host that in Design Studio.

Now, you’re just hosting the same JS that calls the FormsPlus.emailPattern function, the JS library is nowhere to be found.

jinawatson
Level 2

Re: Blocking Spam & Personal Domains Issue

Thanks Sanford - that link didn't work for me. Is there another link for me to download the library file?

SanfordWhiteman
Level 10 - Community Moderator

Re: Blocking Spam & Personal Domains Issue

The forum had mangled the URL, click it again now.

jinawatson
Level 2

Re: Blocking Spam & Personal Domains Issue

It looks like that's the file I already have installed on Design Studio.

jinawatson_0-1711646849556.png

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Blocking Spam & Personal Domains Issue

Nope, you have a file with that name, but it has the wrong content.

jinawatson
Level 2

Re: Blocking Spam & Personal Domains Issue

Okay - I replaced it when the file you linked, but next question is where does this go then?

 

/*
 * @author Sanford Whiteman
 * @version v1.1 2020-11-15
 * @copyright © 2020 Sanford Whiteman
 * @license Hippocratic 2.1: This license must appear with all reproductions of this software.
 *
 *
 *
 */

(function () {
   const invalidDomains = [
      "gmail.com", 
      "yahoo.com", 
      "hotmail.com",
      "sandy@fig1.com",
      "jourrapide.com",
      "teleworm.us",
      "armyspy.com",
      "rhyta.com",
      "cuvox.de",
      "dayrep.com",
      "einrot.com",
      "fleckens.hu",
      "gustr.com",
      "superrito.com",
      "sandy@fig1.net"
      ]
      invalidMessage = "Must be a Business email.";

   const interestingEmailField = "Email";

   /* NO NEED TO ALTER BELOW THIS LINE */

   MktoForms2.whenReady(function (mktoForm) {
      const formEl = mktoForm.getFormElem()[0],
         emailEl = formEl.querySelector("[name='" + interestingEmailField + "']");

      mktoForm.onValidate(extendedEmailValidation);

      function extendedEmailValidation(nativeValid) {
         if (nativeValid === false) return;

         let currentValues = mktoForm.getValues(),
            originalSubmittable = mktoForm.submittable(),
            email = currentValues[interestingEmailField];

         if (email) {
            if (FormsPlus.emailPattern.match(email, invalidDomains)) {
               console.log("Email matches pattern, forcing submittable(false)");
               emailEl.classList.add("customInvalid");
               emailEl.setAttribute("aria-invalid", "true");
               mktoForm.submittable(false);
               mktoForm.showErrorMessage(invalidMessage, MktoForms2.$(emailEl));
            } else {
               console.log("Email does not match pattern, continuing");
               emailEl.classList.remove("customInvalid");
               emailEl.setAttribute("aria-invalid", "false");
               mktoForm.submittable(originalSubmittable);
            }
         }
      }
   });
   
})();
dtavangar
Level 2

Re: Blocking Spam & Personal Domains Issue

Jo_Pitts1
Level 10 - Community Advisor

Re: Blocking Spam & Personal Domains Issue

@dtavangar , I'm not quite sure what you were responding to here?

Jo_Pitts1
Level 10 - Community Advisor

Re: Blocking Spam & Personal Domains Issue

@jinawatson,

if I'm reading things correctly, inside <script> and </script> tags on the page with the form.

Cheers

Jo