Hi All,
We have a situation where we need to create a lead in instance B based on the form fill out of instance A. The problem here is we have different pod urls for instance A (//app-sj25.marketo.com) and B (//app-sjf.marketo.com).
Is it possible to create leads in instance B based on the form fill out of instance A?
Thanks.
Solved! Go to Solution.
It's done like so:
MktoForms2 :: Cross-Post to another Marketo
(Was working on a blog post about why it needs to be done this way a couple of months ago -- will get back it now that the code is fleshed out.)
Below is the js code that we are using in the landing page of instance A to submit the forms.
<script src="//app-XXX.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_1780"></form>
<form id="mktoForm_1024" style="display:none;"></form>
<script>MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", 1780);</script>
<script>MktoForms2.loadForm("//app-YYY.marketo.com", "YYY-YYY-YYY", 1024);</script>
<script>
MktoForms2.whenReady(function (form) {
var emailAddress ;
form.onSubmit(function(){
var valuesForm1780 = form.getValues();
emailAddress = valuesForm1780.Email;
});
form.onSuccess(function(){
//on suucess of the form1 submission, we are submitting the second the second form
var secondForm = MktoForms2.allForms()[0].getId()==1780?MktoForms2.allForms()[1]:MktoForms2.allForms()[0];
secondForm.setValues({"Email":emailAddress});
secondForm.submit();//second form submission
});
});
</script>
C'mon, post the real code, not obfuscated, so I can tell you how it's done.
Also please highlight using the Advanced Editor's Syntax Highlighter:
Please find below details.
Landing Page: https://mkto.test.com/Contact-Us-Simple_LP.html
Custom HTML with form details:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Lead Creation Test</title>
</head>
<body>
<h2>Lead Creation Test</h2>
<p>Lead creation test page.
</p>
<script src="//app-xxx.marketo.com/js/forms2/js/forms2.js"></script>
<form id="mktoForm_A"></form>
<form id="mktoForm_B" style="display:none;"></form>
<script>
MktoForms2.loadForm("//app-XXX.marketo.com", "XXX-XXX-XXX", A);
</script>
<script>
MktoForms2.loadForm("//app-YYY.marketo.com", "YYY-YYY-YYY", B);
</script>
<script>
MktoForms2.whenReady(function(form) {
var fname;
var lname;
var emailAddress;
let check = 0;
form.onSubmit(function() {
console.log('check in onSubmit' + check);
if (check === 0) {
var valuesFormA = form.getValues();
fname = valuesFormA .FirstName;
lname = valuesFormA .LastName;
emailAddress = valuesFormA .Email;
}
});
form.onSuccess(function(form) {
check = check + 1;
if (check <= 1) {
emailAddress = 'ABC-' + emailAddress;
fname = 'ABC-' + fname;
lname = 'ABC-' + lname;
var secondForm = MktoForms2.allForms()[0].getId() == A? MktoForms2.allForms()[1] : MktoForms2.allForms()[0];
secondForm.addHiddenFields({
"Email": emailAddress
});
secondForm.addHiddenFields({
"FirstName": fname
});
secondForm.addHiddenFields({
"LastName": lname
});
console.log(emailAddress);
secondForm.submit();
window.location.href = 'https://mkto.TEST.com/contact-us-conf.html';
}
});
});
</script>
</body>
</html>
OK, thanks, now I can look at something.
Right away, I can see this is needlessly confusing:
var secondForm = MktoForms2.allForms()[0].getId() == 1780 ? MktoForms2.allForms()[1] : MktoForms2.allForms()[0];
If the "first" and "second" forms always have the same ID, there's no reason to go through these motions.
And MktoForms2.whenReady doesn't mean all forms are ready, so you can't immediately start checking indexes in allForms().
Anyway, the whole thing needs to be refactored and I can show you how it's done.
Sure Thanks!
It's done like so:
MktoForms2 :: Cross-Post to another Marketo
(Was working on a blog post about why it needs to be done this way a couple of months ago -- will get back it now that the code is fleshed out.)
Thank you very much!! Sanford Whiteman
Thank you for this, I've got no experience with JS and was able to get it working.
I just had to add the "checksum" and "checksumFields" to the list of fields to remove (alongside mkt_trk) since I believe they added this validation after this solution was posted.
Great to hear — yes, those are new. There’s also a new multi-Marketo-Forms-manager library that I’ve blogged about.