Forms 2.0 & Custom Validation Rules | Community
Skip to main content
February 27, 2014
Solved

Forms 2.0 & Custom Validation Rules

  • February 27, 2014
  • 5 replies
  • 2178 views
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>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by
Hey Chris,

We changed the way form submissions function in Forms 2.0, which is causing the original script to break.

I'd point you to the Forms 2.0 js api documentation at http://developers.marketo.com/documentation/websites/forms-2-0/

Specifically, the last example should point you in the right direction as to how you would set-up this validation rule on email addresses.

Hope this helps!

Thanks,

Jason

5 replies

Dan_Stevens_
Level 10
February 27, 2014
Appears to be working for me.  What's the issue?
February 27, 2014
Sorry, Fail to me on explaining the validation.

We made some validation to prohibit personal email addresses (with the exception of gmail)

So if you put in an address that contains "@yahoo.com" as an example, the old form will not allow you to submit, whereas the new form will submit it - which is the problem.
Accepted solution
February 28, 2014
Hey Chris,

We changed the way form submissions function in Forms 2.0, which is causing the original script to break.

I'd point you to the Forms 2.0 js api documentation at http://developers.marketo.com/documentation/websites/forms-2-0/

Specifically, the last example should point you in the right direction as to how you would set-up this validation rule on email addresses.

Hope this helps!

Thanks,

Jason
February 28, 2014
Thanks Jason, that should help.

However, if anyone has this particular type of validation updated for Forms 2.0 and would like to share it, that would be greatly appreciated!
Jason_Scott
Level 4
July 22, 2014
Anyone have example code they want to share?