Background mktoForm Submission code — where is my error? | Community
Skip to main content
New Participant
May 19, 2022
Solved

Background mktoForm Submission code — where is my error?

  • May 19, 2022
  • 1 reply
  • 1126 views

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>

 

 

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

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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
May 19, 2022

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.