Block Form Submission from Specific Email Account | Community
Skip to main content
December 1, 2015
Question

Block Form Submission from Specific Email Account

  • December 1, 2015
  • 3 replies
  • 1565 views

Hi -- We have a select few companies who fill out our contact us form with the same message on a regular basis, and we would like to block these companies from doing so. Is there a way to do this? Are we able to either send them an error message or not record their submission? Thanks, Stephanie

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Grégoire_Miche2
Level 10
December 1, 2015

Hi Stephanie Bradbury​,

This can easily be done with a few lines of Javascript to be added, using the forms 2.0 API. Forms 2.0 » Marketo Developers

-Greg

December 1, 2015

That's can be done using Forms 2.0.

Here a snippet of JS that can be used to solve your problem:

<script src="//app-abj.marketo.com/js/forms2/js/forms2.min.js"></script> <form id="mktoForm_xxxx"></form>

<script>MktoForms2.loadForm("//app-abj.marketo.com", "xxx-xxx-xxx", xxxx);</script>

<script>

(function (){

  var invalidCompanies = ["abc"];

  MktoForms2.whenReady(function (form){

    form.onValidate(function(){

      var company = form.vals().CompanyName;

      if(company){

        if(!isGoodBusiness(company)) {

          form.submitable(false);

          var companyElem = form.getFormElem().find("#CompanyName");

          form.showErrorMessage("Sorry, this company does not work.", companyElem);

        }else{

          form.submitable(true);

        }

      }

    });

  });

  function isGoodBusiness(testCompany) {

    for(var i=0; i < invalidCompanies.length; i++) {

      var company = invalidCompanies[i];

      if (testCompany.indexOf(company) != -1) {

        return false;

      }

    }

    return true;

  }

})();

</script>

SanfordWhiteman
Level 10
December 1, 2015

That'll catch 'Zabco', though. You probably want an exact match.

(Also, I don't know if the OP meant literally the Company field or the email domain.)

December 1, 2015

Sanford,

just an example. It needs to be tested and changed accordingly with the appropriated fields.