Multiple Marketo forms on a single page

mounica_tunugun
Level 2

Multiple Marketo forms on a single page

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.  

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Multiple Marketo forms on a single page

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.

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Multiple Marketo forms on a single page

 

<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
Level 2

Re: Multiple Marketo forms on a single page

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
Level 10 - Community Advisor + Adobe Champion

Re: Multiple Marketo forms on a single page

 

 

 

<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:

mounica_tunugun
Level 2

Re: Multiple Marketo forms on a single page

Hi @Darshil_Shah1 Thanks for the reply.

But it's still the same. On submit It's redirecting  for both the forms.

SanfordWhiteman
Level 10 - Community Moderator

Re: Multiple Marketo forms on a single page

Please go back and use the syntax highlighter on your original code so it's readable, then we can continue.