This post originally appears on the Marketo Developers Blog
When your organization has many different platforms for hosting web content and customer data it becomes fairly common to need parallel submissions from a form so that the resulting data can be gathered in separate platforms. There are several strategies to do this, but the best one is often the simplest: Using the Forms 2 API to submit a hidden Marketo form. This will work with any new Marketo Form, but ideally you should create an empty form for this, which has no fields:
This will ensure that the form doesn’t load any more data than necessary, since we don’t need to render anything. Now just grab the embed code from your form and add it to the body of your desired page, making a small modification. You embed code includes a form element like this:
You’ll want to add ‘style=”display:none”‘ to the element so it is not visible, like this:
<form id="mktoForm_1068" style="display:none"></form>
Once the form is embedded and hidden, the code to submit the form is really quite simple:
var myForm = MktoForms2.allForms();
//These are the values which will be submitted to Marketo
Forms submitted this way will behave exactly like if the lead had filled out and submitted a visible form. Triggering the submission will vary between implementations since each one will have a different action to prompt it, but you can make it occur on basically any action. The important part is setting your fields and values correctly. Be sure to use the SOAP API name of your fields which you can find with Export Field Names to esnure correct submission of values.
It appears I am late to the dance with this but it seems with new code releases I can't post my CMS forms to https://app-ab1512.marketo.com/index.php/leadCapture/save soooooo
Trying to get the below code to fire from a completely blank page and reloading it but it does not seem to want to fire. And now getting the error in console: mktoForm_1081 is undefined
MktoForms2.loadForm("//app-ab1512.marketo.com", "110-GBK-212332", 1081);
var mktoForm_1081 = MktoForms2.allForms();
I didn't see there was another 50 responses hidden...oooops... found the goods up there
This was a great approach. I modified the code a bit for my needs.
Thanks for the great post and all the comments! I've actually been trying to submit the same form multiple times (but more than twice) to register multiple users using 1 form. I've been successful at submitting the form twice but anything beyond that I can't seem to be able to do it. I've tried many different things and still can't seem to figure it out, my goal is to not have many hidden forms so that I can easily reuse this code for other pages and forms. The forms are being loaded just not via code.
Below is the code that I got from one of SanfordWhiteman's posts. In my form I have a particular field that they can choose the number of users they want to register 1-5 and based on that number different fields will show up for the user to enter First/Last/Email for each.
My goal is to use a for loop to iterate over the submission
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.