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

Level 10 - Community Moderator

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

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.

Level 5

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

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?

Level 10 - Community Moderator

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

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

Level 5

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

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

Level 10 - Community Moderator

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


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.

 

Level 5

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

Thanks Sanford!