Skip to main content
February 20, 2015
Question

Embedded form 2.0 - need it to call an exteranl script on submit

  • February 20, 2015
  • 1 reply
  • 860 views
Looking for the JS guru's out there.  I have the standard embed code for a Forms 2.0 script on a webpage, but I have a rather long validation script to look for fake/temp. email addresses.  I need the embed script to also call to my external script when the "submit" button is clicked.

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

1 reply

SanfordWhiteman
Level 10
February 21, 2015
Use the onValidate handler as in the Forms 2.0 API docs.

<script src="//app-sj01.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_96"></form>
<script>MktoForms2.loadForm("//app-zz01.marketo.com", "AAA-BBB-CCC, 96,
    function(form) {   
  form.onValidate(function(){
    // I'm checking a sample condition - this is where you'd call your external validation script
    if(form.vals().LastName != "Go For It"){
      //prevent form submission
      console.log('setting unsubmittable (submit step will not run) - try again');
      form.submittable(false);
    }else{
      //enable submission for those who met the criteria.
      console.log('setting submittable (submit step will run next)');
      form.submittable(true);
    }
    })
    });
</script>

Running here.