SOLVED

Re: Forms 2.0 & Custom Validation Rules

Go to solution
Anonymous
Not applicable

Forms 2.0 & Custom Validation Rules

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>
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Forms 2.0 & Custom Validation Rules

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

View solution in original post

5 REPLIES 5
Dan_Stevens_
Level 10 - Champion Alumni

Re: Forms 2.0 & Custom Validation Rules

Appears to be working for me.  What's the issue?
Anonymous
Not applicable

Re: Forms 2.0 & Custom Validation Rules

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.
Anonymous
Not applicable

Re: Forms 2.0 & Custom Validation Rules

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
Anonymous
Not applicable

Re: Forms 2.0 & Custom Validation Rules

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

Re: Forms 2.0 & Custom Validation Rules

Anyone have example code they want to share?