AnsweredAssumed Answered

Forms 2.0 & Custom Validation Rules

Question asked by 349c11c66c74266ee584a2b73d7e7ae8655ac924 on Feb 27, 2014
Latest reply on Jul 21, 2014 by Jason Scott
Hello all,

I've run into a problem with Forms 2.0. The validation that I have on my pages for email addesses is not working with the new forms, yet it still works for the old forms.

Old Form
http://pages.datacore.com/testpageoldform.html

New Form
http://pages.datacore.com/Testpagenewform.html

Do I need to change something in the javascript? Or is it something else that I missed. See javascript below.

<script type="text/javascript" src="/js/public/jquery-latest.min.js" language="Javascript"></script>
<script type="text/javascript">

    // set no conflict mode for jquery
  var $jQ = jQuery.noConflict();
    //edit this list with the domains you want to block
  var invalidDomains = ["@123.com",
"@123box.net",
"@etc....",
];

  function formSubmit(elt) {
      // run the custom validation.  If it succeeds, run the Marketo validation
    if (!isEmailGood()) {
       Mkto.setError($jQ("#Email ~ span").prev()[0],"The address must be from a business address, not a free service");
       return false;
    } else {
       Mkto.clearError($jQ("#Email ~ span").prev()[0]);
    }
    return Mkto.formSubmit(elt);
  }

  function isEmailGood() {
    for(i=0; i < invalidDomains.length; i++) {
      if ( $jQ("#Email[value*=" + invalidDomains[i] + "]").length > 0) {
          return false;
      }

    }
    return true;
  }
</script>

Outcomes