Is it possible to create leads in instance B based on the form fill out of instance A? | Community
Skip to main content
October 12, 2018
Solved

Is it possible to create leads in instance B based on the form fill out of instance A?

  • October 12, 2018
  • 2 replies
  • 8112 views

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.

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

Please find below details.

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


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.)

2 replies

Jay_Jiang
New Participant
October 14, 2018

An alternate solution would be to create a smart campaign triggering off filled out form and calling a webhook and posting to the index.php/save endpoint of your 2nd instance

October 16, 2018

Hi Jay, thanks for the suggestion. We wanted to reduce the API calls and Sanford's solution is working for us.

Jay_Jiang
New Participant
October 16, 2018

Good to hear. But just to clarify, webhooks here don't use any API calls.

October 12, 2018

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>

SanfordWhiteman
New Participant
October 12, 2018

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:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

October 12, 2018

Please find below details.

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