Re: How lead token can be used with thank you page URL?

Sant_Singh_Rath
Level 7

I want to add lead token in the thankyou page url and thank you page is created in the wordpress but when I tried to add and save it, it is not letting me do it. It says I can only add my. token with the url.

Screen Shot 2019-03-06 at 12.12.29 pm.png

Any suggestions how I can do this?

Best regards,
Sant Singh Rathaur
15 REPLIES 15
SanfordWhiteman
Level 10 - Community Moderator

The final lead in the database is not fully resolved at the point the Thank You page is selected.

It would not be possible to reference fields present on an existing lead due to be merged with the posted data. Hence the capability as a whole is not offered.

You can use the fields from the form post itself to select the Thank You URL, of course.

Sant_Singh_Rath
Level 7

Thanks Sanford Whiteman​! Got it done by adding custom javascript code finally.

Best regards,
Sant Singh Rathaur
SanfordWhiteman
Level 10 - Community Moderator

Not for fields that weren't in the form post itself, presumably.

Sant_Singh_Rath
Level 7

Yeah! We collected the information through form fields and same details was required to populate in the thank you page url. (just because agency needed it)

Best regards,
Sant Singh Rathaur
Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

Hi Sant,

I just came across this post researching exactly the same use case. Could you tell me a little bit more about the JS you required to make it work?

Thanks!

Kind regards,
Katja

SanfordWhiteman
Level 10 - Community Moderator

Are you trying to use a field that was submitted on the form?

Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

A hidden field on the form, yes (copy of the lead id field actually).

SanfordWhiteman
Level 10 - Community Moderator

You can use a standard pattern which I'll add to the Products Blog this wknd.

Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

You're a gem.

SanfordWhiteman
Level 10 - Community Moderator

So really it's as simple as

MktoForms2.whenReady(function(mktoForm){   
   mktoForm.onSuccess(function(submittedValues,originalThankYouURL){
      let originalThankYouLoc = document.createElement("a"),
          finalThankYouLoc = document.createElement("a");

      originalThankYouLoc.href = originalThankYouURL;
     
      if (submittedValues.someFormField == "value1") {
         finalThankYouLoc.href = "https://www.example.net/some/page/dependent/on/value1";
      } else if (submittedValues.someFormField == "value2") {
         finalThankYouLoc.href = "https://www.example.org/some/page/dependent/on/value2";
      } else if (submittedValues.someFormField == "value3") {
         finalThankYouLoc.href = "https://www.example.edu/some/page/dependent/on/value3";         
      }

      finalThankYouLoc.search += (finalThankYouLoc.search ? "&" : "") + originalThankYouLoc.search;
      document.location = finalThankYouLoc;
      
      return false;
   });
});

The key being that you need to append the original Thank You URL's query string to the new URL's query string, because it includes the important aliId parameter.

Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

Ah yikes, that does mean the form field should have a limited number of predefined values. Wouldn't work with a personal id by the look of it?

SanfordWhiteman
Level 10 - Community Moderator

Not sure what you mean. What's the relationship between the field and the TY URL?

Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

The hope was to add the lead id as parameter to a calendly page to book an appointment.

SanfordWhiteman
Level 10 - Community Moderator

The hope was to add the lead id as parameter to a calendly page to book an appointment.

So just set the TY URL instead of the if() conditions:

finalThankYouLoc.href = "https://calendly.com/" + encodeURIComponent(submittedValues.someFormField);

 

or more standards-y:

finalThankYouLoc.href = "https://calendly.com";
finalThankYouLoc.pathname = "/" + encodeURIComponent(submittedValues.someFormField);

 

or whatever structure fits the final URL. Just make sure to always URI-encode.

 

Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

Thanks Sanford!