Marketo Form Submit

HTML

<script src="//app-ab07.marketo.com/js/forms2/js/forms2.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<form id="test-form" method="POST">
  <input name="email" type="text">
   <input name="firstname" type="text">
  <input name="submit" type="submit">
</form>

<form id="test-form2" method="POST">
  <input name="email2" type="text">
   <input name="firstname2" type="text">
  <input name="submit2" type="submit">
</form>

<a href="javascript:void(0)" id="btnClick">click</a>

JavaScript

MktoForms2.loadForm("//app-ab07.marketo.com", "920-LJZ-738", 2200);
MktoForms2.whenReady(function(mktoForm) {
mktoForm.onSuccess(function(vals,tyURL){
  return false;
});
  
  var customFormData = {
    formSelector : 'form',
    btnSubmit : '#btnClick',
    fieldMap : [{
      marketo : 'Email' ,
      custom : '[name="email"]' 
    },
    {
    	marketo: 'FirstName',
    	custom: '[name="firstname"]'
    },
    {
    	marketo: 'firstname2',
    	custom: '[name="firstname2"]'
    }]
  }
  
  $(customFormData.btnSubmit).on('click', function(e) {
    var mktoFields = {};
        
    $(customFormData.formSelector).each(function(index) {
	    var customForm = this
      customFormData.fieldMap.forEach(function(field){
      if($(customForm).find(field.custom).length)
        mktoFields[field.marketo] = $(customForm).find(field.custom).val()
      }, customForm);
    })
    
    console.log(mktoFields)

    // add to Marketo form
    mktoForm.addHiddenFields(mktoFields);
    
    // submit Marketo form
    mktoForm.submit();
    
    // stop custom HTML form submission
    e.preventDefault();
  })
});