Forms 2.0 onSubmit Validation Script | Community
Skip to main content
March 18, 2014
Question

Forms 2.0 onSubmit Validation Script

  • March 18, 2014
  • 14 replies
  • 5624 views
When I use the onSubmit validation code from #9 on the Forms 2.0 page  the validation works. However when I change the value in the field that I am trying to validate the form doesn't run through the onSubmit again and the form is unsubmitable. 

View code below:




MktoForms2.loadForm("//app-abk.marketo.com", "###-###-###", 89,function(form){
 
form.onSubmit(function(){
  
   var vals = form.getValues();
   
   if( vals.verify != "Verify" || vals.verify != "verify" ) {
    form.submitable(false);
var verify = form.getFormElem().find("#verify");
form.showErrorMessage("You must type the word 'Verify'", verify);
} else {
form.submitable(true);
}
 
   });
 
form.onSuccess(function(values, followUpUrl){
   form.getFormElem().fadeOut();
   return false;
 });
 
 
});

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

14 replies

Level 4
July 18, 2014
Hi Ian! Thank you for solution, but what if I don't use Marketo form with "Embed Code"?
July 18, 2014
@Ian - thanks for the update - yes the example was updated the day after my post of 7/11/2014 I believe - (although the comment on line 2 still says: "//listen for the submit event" ?)

Just FYI... I think you also need a tested & working example for onFormRender method - as per this conversation with Murza - the API reference on that page claims that the method is on form - but I've discovered it only exists on MktoForms2, so that needs sorting out before it wastes anymore of anyone elses time.

Thanks
Ben
July 18, 2014
Khripunov,

You'd basically just need to create a new HTML Snippet on your landing page and put a <script> </script> tag into it.  Then, inside the body of the script tag, for any of the examples, you'd change the first line so that instead of loading the form, it grabs the form that is already on the page when it's ready:

MktoForms2.loadForm("//app-sjqe.marketo.com", "718-GIV-198", 621, function(form){
becomes
MktoForms2.whenReady( function(form){
July 18, 2014
Ben,

Yes, it looks like the documentation for the whenReady, onFormRender, and whenRendered functions got put in the wrong section of the documentation when it was copied out of our internal documentation resource onto the developer site.  I'll try to get that corrected.  They're not meant to be methods on the form object, they're the way that you get a reference to the form object from a global context when you don't have it yet.