I have a use case where I want a marketo form to pre-populate fields based on url parameters and then automatically be submitted on page load without any user clicks. I would have thought the code below would work, but it doesn't. Instead, the code makes the page reload over and over again. If it matters, the page is a marketo landing page on a marketo server.
Anyone ever tackle this use case before? Any ideas why the code below doesn't work?
<body>
<div class="mktoContent">
<script src="//app-sj11.marketo.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_59"></form>
<script>MktoForms2.loadForm("//app-sj11.marketo.com", "558-YIS-558", 59);</script>
</div>
<script type="text/javascript">
function formAutoSubmit () {
var frm = document.getElementById("mktoForm_59");
frm.submit();
}
window.onload = formAutoSubmit;
</script>
</body>
Solved! Go to Solution.
Check out my blog on a similar topic here: http://developers.marketo.com/blog/make-a-marketo-form-submission-in-the-background/ You would want to use the MktoForms.whenReady method to then call submit() from the form.
So, testing outside of Marketo, I learn that the code above works if there is no submit button code on the form. Not sure how you remove the button input from a Marketo form or work around it.
Check out my blog on a similar topic here: http://developers.marketo.com/blog/make-a-marketo-form-submission-in-the-background/ You would want to use the MktoForms.whenReady method to then call submit() from the form.
Thank you!
I like this article, thanks for posting it
Definitely use Kenny's Forms 2.0 API method. Don't treat Marketo forms like generic forms.
But also, if the form's Thank You logic reloads the same page, then you will trigger the logic again, which you definitely don't want. Instead, you should either redirect to another page that doesn't auto-submit (based on query string or a totally different URL) or change the redirect logic to just stay put on the current page.
Couldn't this be more easily accomplished in a workflow? Visits Web Page in the smart list and then some formalized change data value steps in the flow.
Not really, because URL parsing isn't going to happen in the CDV step.
I have a similar use case, and from the resources above I think I've cracked most of it. But for some reason, the form is submitting multiple times before it redirects (up to 6 times!)
Here is the code. I've put this at the bottom of a Marketo guided landing page template:
<script>
MktoForms2.loadForm("//app-ab06.marketo.com", "110-AIL-152", 1417, function(form) {
// From here we have access to the form object and can call its methods
MktoForms2.whenReady(function (form) {
form.submit();
});
//Add an onSuccess handler
form.onSuccess(function(values, followUpUrl) {
// Take the lead to a different page on successful submit, ignoring the form's configured followUpUrl
location.href = "http://www.google.com";
// Return false to prevent the submission handler continuing with its own processing
return false;
});
});
</script>
Maybe I don't need the custom redirect code in the second half - a bit unsure! Any guidance appreciated
Phil
Please post a link to your page. The redirect loop shouldn't happen if you're going to a page built off another template.
You don't need custom onSuccess if you want to use the value from Form Editor.