SOLVED

Re: Background mktoForm Submission code — where is my error?

Go to solution
aayushror
Level 2

Background mktoForm Submission code — where is my error?

Hi There, 

I hope someone can help with this. I'm using the code below,  to pass the values from our custom HTML form into Marketo, it works fine for most cases. However, I do see sometimes the form creates an empty lead and some leads don't show up in our Marketo instance. Can someone please advise If I am missing something or how to resolve that issue?

Thanks,

 

<script>
	function SubmitForm(event) {
        var form = MktoForms2.allForms()[0];
        var fEmail = $('#f_email').val();
        var fName = $('#f_name').val();
        var fLast = $('#l_name').val();
        var fCompany = $('#company').val();
        var fPlatform = $('#platform').val();
        if( (fEmail != "") && (fName != "") && (fCompany != "") && (fLast != "") && (fPlatform != "")){
          form.addHiddenFields({
            "Email": fEmail,
            "FirstName": fName,
            "LastName": fLast,
            "Company": fCompany,
            "Platform_c": fPlatform        
          });
     
       form.submit();
    }
        };
</script>

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Background mktoForm Submission code — where is my error?

There’s nothing glaringly wrong with what you’ve shown here except you shouldn’t just using the first Marketo form.

 

Wait for the proper JS API event and (if necessary) determine the whether it’s the right form using getId():

function SubmitForm(event) {
    MktoForms2.whenReady(function(mktoForm){
       // can check mktoForm.getId() here
       var fEmail = $('#f_email').val();
       var fName = $('#f_name').val();
       var fLast = $('#l_name').val();
       var fCompany = $('#company').val();
       var fPlatform = $('#platform').val();
       if( (fEmail != "") && (fName != "") && (fCompany != "") && (fLast != "") && (fPlatform != "")){
         mktoForm.addHiddenFields({
            "Email": fEmail,
            "FirstName": fName,
            "LastName": fLast,
            "Company": fCompany,
            "Platform_c": fPlatform        
         });
         mktoForm.submit();    
       }
  });
}

 

We aren’t seeing the rest of your code but a lead without an email address can’t be created by this function.

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Background mktoForm Submission code — where is my error?

There’s nothing glaringly wrong with what you’ve shown here except you shouldn’t just using the first Marketo form.

 

Wait for the proper JS API event and (if necessary) determine the whether it’s the right form using getId():

function SubmitForm(event) {
    MktoForms2.whenReady(function(mktoForm){
       // can check mktoForm.getId() here
       var fEmail = $('#f_email').val();
       var fName = $('#f_name').val();
       var fLast = $('#l_name').val();
       var fCompany = $('#company').val();
       var fPlatform = $('#platform').val();
       if( (fEmail != "") && (fName != "") && (fCompany != "") && (fLast != "") && (fPlatform != "")){
         mktoForm.addHiddenFields({
            "Email": fEmail,
            "FirstName": fName,
            "LastName": fLast,
            "Company": fCompany,
            "Platform_c": fPlatform        
         });
         mktoForm.submit();    
       }
  });
}

 

We aren’t seeing the rest of your code but a lead without an email address can’t be created by this function.