Multiple Marketo forms on a single page | Community
Skip to main content
mounica_tunugun
New Participant
April 3, 2020
Question

Multiple Marketo forms on a single page

  • April 3, 2020
  • 2 replies
  • 6533 views

Hi there, 

I have a Post page in that i'm using 2 forms. One is for subscription and another one is for downloading the post.

For downloading post form after submit i'm redirecting to thank you page with a download link on that thank you page.

For subscription I just want to display a text message in that post page itself. Which is working fine in remaining posts which don't have any other marketo forms in that particular page.

But when 2 forms are there in a single page download form is over writing the subscription form script  (means after showing thank you message it is also redirecting to thank you page ,which is not necessary). Can anyone help me in fixing that.

Thanks in advance.  

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

2 replies

Darshil_Shah1
Community Manager
April 3, 2020

 

<script src="//app-XXXX.marketo.com/js/forms2/js/forms2.min.js"></script> //You can find your instance specific script source from embed form option in your respective instance. <script> MktoForms2.whenReady(function(form) { var formId = form.getId(); if(formId==<formid>) { //Insert formid for form1 form.onSuccess(function(){ alert("Form 1 successfully submitted"); //Write what you wish to do when form 1 is submitted }); } else if (formId==<formid>) { //Insert formid for form2 form.onSuccess(function(){ alert("Form 2 successfully submitted"); //Write what you wish to do when form 2 is submitted }); } });

 

Add this script to your LP. Also if you want any help regarding the code for onSuccess (when the form is successfully submitted)  as Sanford told you need to give us more information. This a generic code to do different things based on which marketo forms is submitted from the single landing page having multiple marketo forms. Hope it helps. Let us know if you want more help 🙂

 

mounica_tunugun
New Participant
April 3, 2020

Thanks for the quick response. The following is the code block for 2 forms.

 

<script>
MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", abcd);
MktoForms2.whenReady(function (form){
form.onSuccess(function(values, followUpUrl){
form.getFormElem().hide();
document.getElementById('confirmform').style.display = 'block';
return false;
});
});
</script> This i'm using to display thank you message.

<script>

MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", WXYZ);
MktoForms2.whenReady(function(form) {
form.onSuccess(function(vals, tyURL) {
var tyLoc = document.createElement("a");

tyLoc.href = tyURL;
var res = '<?php echo get_field('XXXXX'); ?>';
tyLoc.search += "?" + res;
document.location = tyLoc;

return false;
});
form.onSuccess(function(values, followUpUrl){
// Set cookies
Cookies.set("_XXXX", '<?php echo $req; ?>');
Cookies.set("_XXX", '<?php echo $xyz; ?>');
//Cookies.set("_XXX", followUpUrl);

// Prevent default
return false;
});
});
</script> This block of code i'm using for thank you page redirect.

Darshil_Shah1
Community Manager
April 3, 2020

 

 

 

<script> MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", abcd); MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", WXYZ); MktoForms2.whenReady(function(form) { var formId = form.getId(); if(formId==abcd) { //Insert formid for form1 form.onSuccess(function(values, followUpUrl){ form.getFormElem().hide(); document.getElementById('confirmform').style.display = 'block'; }); } else if (formId==WXYZ) { //Insert formid for form2 form.onSuccess(function(vals, tyURL) { //Set cookies before redirection Cookies.set("_XXXX", '<?php echo $req; ?>'); Cookies.set("_XXX", '<?php echo $xyz; ?>'); //Cookies.set("_XXX", followUpUrl); var tyLoc = document.createElement("a"); tyLoc.href = tyURL; var res = '<?php echo get_field('XXXXX'); ?>'; tyLoc.search += "?" + res; document.location = tyLoc; // Prevent default }); } }); </script>

 

Try this:

SanfordWhiteman
New Participant
April 3, 2020

If you don't supply the code you're trying to use (and the URL it's running on) there's no way to tell you what's wrong with it.