Re: Form Follow up with to relative external Thank you Page URL

Prakash_Mohanda
Level 2

Hello

This might be a very simple question. I am basically trying to create form that is being embedded on a web page called 'get-started' but the form should automatically redirect to a relative 'thank you' page that is one level down in the hierarchy 'get-started/thank-you' . How do I setup a redirect to a relative page on the website that this form is located on?

14 REPLIES 14
Michael_Tucker1
Level 4

HI Prakash Mohandas​,

I think that if you give this code a try instead of your standard Marketo embed form, that should redirect to the landing page you're talking about here:

<script src="//app-ab22.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_4"></form>

<script>MktoForms2.loadForm("//app-ab23.marketo.com", "876-MVP-978", 4, function(form) {

    form.onSuccess(function(values, followUpUrl) {

        location.href = "https://ibs.schwab.acsitefactory.com/get-started/thank-you";

        return false;

    });

});</script>

Does that help?

Michael

Michael Tucker
SanfordWhiteman
Level 10 - Community Moderator

MktoForms2.whenReady(function(form){

  form.onSuccess(function(vals,tyURL){

    var loc = document.createElement('A');

    loc.href = tyURL;

    loc.pathname = [loc.pathname,"thank-you"].join("/");

    document.location.href = loc.pathname + loc.search + loc.hash;

    return false;

  });

});

Prakash_Mohanda
Level 2

Thank you Sanford. Where does this code go? or where does this code need to be added?

Prakash_Mohanda
Level 2

Currently my ember code is

<script src="//app-ab22.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_4"></form>

<script>MktoForms2.loadForm("//app-ab22.marketo.com", "876-MVP-978", 4);</script>

SanfordWhiteman
Level 10 - Community Moderator

Right after the embed code, in a <script>.

Prakash_Mohanda
Level 2

I added the code.
However  The submit button is going to https://thank-you, instead of  /get-started/thank-you.

Prakash_Mohanda
Level 2

The Marketo form is located at: https://ibs.schwab.acsitefactory.com/get-started.

The thank-you page is located at: https://ibs.schwab.acsitefactory.com/get-started/thank-you,
so the link needs to be t

The Marketo form is located at: https://ibs.schwab.acsitefactory.com/get-started.

The thank-you page is located at: https://ibs.schwab.acsitefactory.com/get-started/thank-you,
so the link needs to be the relative link of /get-started/thank-you.

he relative link of /get-started/thank-you.

SanfordWhiteman
Level 10 - Community Moderator

The code expects you to still have a Thank You URL entered in the Form Editor, because you may want to add query params and hash at some point.

Then it swaps out the path of the Thank You URL for the relative path (but it keeps the query and hash -- search and hash -- of the URL).

Samantha_Cossum
Level 3

Sanford Whiteman​, Is it possible to do this without it being a local page? We have implemented standard lead gen form that are used across a number of domains. All the thank you pages are relative to the domain the form is posted on but it could be posted on several domains so having it look at a "default" url and then just edit the path wouldn't work.

Right now we try to use choices but we have problems with the person crafting the campaign communicating where a page needs to go based on the utm and then automatically jumps to it being broken. Would love to give our web developer a fix up front that he can implement when he's creating the pages.

Thanks!

SanfordWhiteman
Level 10 - Community Moderator

Is it possible to do this without it being a local page?

Of course, the code was simply written for the OP's needs.

If you want to stay on the same hostname that hosted the form (i.e. current hostname), and append the path + pagename + query from the Thank You URL, then do:

MktoForms2.whenReady(function(form){ 

  form.onSuccess(function(vals,tyURL){ 

    var tyLoc = document.createElement('A'); 

    tyLoc.href = tyURL; 

    tyLoc.protocol = document.location.protocol;

    tyLoc.host = document.location.host;

    document.location = tyLoc;

    return false; 

  }); 

});

Samantha_Cossum
Level 3

This is awesome! Our web developer already tested it out and it worked like a charm so thank you!

Prakash_Mohanda
Level 2

Hi Sanford. hoping for an answer on this . thx !

Prakash_Mohanda
Level 2

The form does currently have a url 'https://www.schwab.com' listed in the follow up with  field as an external URL. are you talking about something else?

Prakash_Mohanda
Level 2