- Hiding a form after submission and blocking early submissions both use simple onSuccess and submittable() handlers.
- Hidden fields can carry a submission timestamp or pass data quietly along with a completed form.
- The MktoForms2 object contains the core methods (loadForm, onFormRender, whenReady) developers use to control forms.
- Non-Marketo forms can still feed lead data into Marketo with a bit of custom JavaScript.
- Munchkin tracking and content-gating features (Known Visitor HTML) let marketers control what visitors see and how they're tracked.
Marketo has been huge for marketing automation. We can hardly imagine what it would be like to go back to doing automated marketing without it.
One of Marketo’s greatest strengths is its web forms. Marketo’s Form Editor and Forms APIs have tremendous flexibility and potential. Both contribute heavily to Marketo’s reputation as one of the top marketing automation solutions. View our comparison between Marketo and Hubspot for marketing automation.
However, with great power comes great complexity. To wield the full potential of Marketo forms, it is necessary to understand how best to utilize them. It’s especially important to have a sense of what you can accomplish with Marketo’s included features and what might need to be customized by your dev team.
Watch one of our webinars to learn more about marketing automation in Marketo. Sign-up today!
Also, if you’re thinking about using Marketo or upgrading your Marketo skills to take an existing implementation to the next level, This article is for you.
Let’s review common questions that marketers frequently encounter when building campaigns with Marketo. We hope this FAQ will help you achieve true Marketo mastery.
Frequently asked questions about Marketo forms
Q: How do I hide a Marketo form after submission?
Use an onSuccess handler that hides the form element, so the form disappears as soon as the lead submits it. When a previously-submitted form hangs around like the worst guest at a house party, your lead starts wondering if they actually submitted the form correctly or if you’re just bad at web coding.
Here’s an onSuccess handler that does it. You can find more detailed examples of the code we’re showing you in context on Marketo’s site for this and the next two questions:
form.onSuccess(function(values, followUpUrl) {
form.getFormElem().hide();
return false;
});
Once the user clicks “submit,” they’ll never see the form again – unless you choose to make it reappear for some reason.
Q: How do I prevent a user from submitting a Marketo form?
Call form.submittable(false) to stop a user submitting a Marketo form until the conditions you define are met. If you want to make it impossible for a user to submit a form, this will do the trick:
if (form.submittable()) {
form.submittable(false);}
});
Defining the conditions that “unlock” the form is another question entirely. In its example, Marketo includes code that makes the form submittable again only after a button has been clicked three times.
Q: How do I set values in a hidden Marketo field form?
Use form.vals() to load preset values into hidden fields you’ve already set up in the Form Editor. Sometimes, you want a submitted form to carry a little payload of information that your lead can’t see.
Assuming you’ve configured some hidden fields in the form editor when you created your form, this code lets you load those fields with preset values:
form.vals({"hiddenField1":"true", "hiddenDate":"2019-01-01"});
In a later question, you’ll see how you can use hidden fields to discreetly hold automatically-generated data for use when running analytics on your form submissions.
Q: What are MktoForms2 methods?
MktoForms2 is an object used in Marketo’s Forms 2.0 API. It’s one of the two main Forms objects you’ll spend most of your time interacting with. It contains functions for creating, loading, and fetching Forms objects.
Here’s a quick rundown of MktoForms2 methods:
- .loadForm()
Loads a form descriptor and creates a new Form object. - .lightbox()
Renders a lightbox-style dialog box with the Form object in it. - .newForm()
Creates a new Form object from a Form Descriptor JavaScript object. - .getForm()
Retrieves a previously-created Form object. - .allForms()
Fetches an array of all Form objects previously constructed on the page. - .getPageFields()
Retrieves a JavaScript object containing data from the URL and referrer. - .whenReady()
Adds a callback that will be called once per Form after it meets certain “ready” conditions. - .onFormRender()
Adds a callback that will be called whenever a Form on the page is rendered. - .whenRendered()
Same as above, but also calls the callback immediately for all forms that have already been rendered.
Q: How can I see form submissions for a given time period?
Add a hidden field that records a timestamp when the form is submitted, then sort and filter submissions by that timestamp. The timestamp method will only enable you to track forms by submission time going forward, not retroactively.
The following code will add a hidden field to a form that records a timestamp when the form is submitted:
MktoForms2.whenReady(function(form){
form.onSubmit(function(form){
form.addHiddenFields({ LastFormFilloutDateTime : new Date().toUTCString() });
});
You can then use the timestamp value to sort and filter submitted forms in any spreadsheet or database program they’ve been exported into.
Q: How can I capture lead information in Marketo from a non-Marketo form?
Pass the third-party form’s data to a hidden Marketo form and submit that form. In theory, this isn’t too difficult to do with a plain HTML form.
Your code needs to catch the HTML “submit” event, transfer the field contents to a bidden Marketo form, and call the Marketo form’s “submit” event.
This can get complicated depending on the types of forms you’re using, but the Marketo community has some coding suggestions for this circumstance.
Q: How do I turn off Munchkin code for Marketo forms?
Clear the Munchkin cookie value in the form code so Marketo stops treating every submission from one device, such as a trade-show tablet, as the same lead. “Munchkin” is what Marketo calls its lead tracking code. The Munchkins do great work serving up cookies and following your leads, but sometimes you may prefer that they make themselves scarce for a while.
For instance, forms for internal use or special events might end up feeding the Munchkins a lot of confusing and unhelpful data.
At a trade show, you might have a tablet set up with a web form to solicit contact information from your visitors. The Munchkins will see all the forms coming through one device and cookie as one single lead (albeit with multiple personalities and email addresses).
This code will clear the Munchkin cookie value upon submission of the form, but does not delete the cookie itself:
MktoForms2.whenReady( function(form){
form.addHiddenFields({"_mkt_trk":""});
form.onSubmit( function(form){
form.vals({"_mkt_trk":""});})
})
The Munchkins will effectively “forget” who submitted the form and you’re free to await the next visitor’s submission.
Q: How can I make a success message show in an embedded Marketo form?
Use an onSuccess handler that replaces the form with an in-line confirmation message. If you don’t want to boot your leadover to a different web page once they’ve successfully submitted your form, an in-line message keeps them on the page. You can even handle more complex situations, like checking for duplicate sign-ups and feeding them a link to an account management page.
Here’s some code for a simple success message:
form.onSuccess(function(values, followUpUrl) {
form.getFormElem().html("Your form has been submitted!");
form.getFormElem().css("text-align","center");
form.getFormElem().css("font-family","'Helvetica'");
return false;
});
Once the lead clicks “submit,” a message appears, letting them know that it went through.
Q: How can I create a Marketo form with two fields in the same row and one field in another row?
Custom CSS works best, though there are a few different ways to approach the problem.
The most effective method may be to use an advanced framework using custom CSS, allowing you to use advanced field customization and placement features. It’s possible to use fixed sizes and the Form Editor to set up a form this way, but the placement will not be consistent on smaller screens.
Q: How can I gate online content using a Marketo form?
Use the Known Visitor HTML setting in the Form Editor to show gated content to visitors once they have submitted the form. Not every page needs a gate, and sometimes it’s better to let visitors read whatever they want on your site. But when you have especially attractive or valuable content, gating it with a form is a great way to pick up some leads.
To turn a form into a content gate, open the Known Visitor HTML feature in the Form Editor settings. This will display custom HTML pages to “known visitors,” a status you can set once they submit the form.
Where can you get more help with Marketo forms?
Marketo’s own how-to guides and community support forums are the best place to go when a Marketo forms question isn’t covered here. No FAQ can address every issue and scenario advanced users will bring to the surface, and Marketo’s other resources can also help get you back on track.
With a little creativity in their design and placement, web forms can help you extract all kinds of great information from your leads. It’s hard to beat Marketo when it comes to putting the full weight of your MarTech stack behind efforts to utilize that information.