Add Variables from Form as Parameters for Thank You Page | Community
Skip to main content
Stephanie_Berr2
New Participant
April 29, 2020
Solved

Add Variables from Form as Parameters for Thank You Page

  • April 29, 2020
  • 2 replies
  • 7358 views

I have a form that I'm looking to send to a calendar scheduling tool after the form is submitted. I want to pass the information they submitted in the form through the URL but cannot figure out how to get these variables into the query string for the thank you page url.

 

Thank you page URL: example.com/meeting

Desired thank you page + query string: example/meeting?name=first%20last&email=john@email.com

 

Best answer by SanfordWhiteman
MktoForms2.whenReady(function(form){ form.onSuccess(function(submittedValues,serverThankYouURL){ var appendValues = { name : submittedValues.FirstName + " " + submittedValues.LastName, email : submittedValues.Email }; /* -- NO NEED TO TOUCH BELOW THIS LINE -- */ var thankYouLoc = document.createElement("a"); thankYouLoc.href = serverThankYouURL; thankYouLoc.search += Object.keys(appendValues).reduce(function(acc,key){ acc += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(appendValues[key]); return acc; }, ""); document.location = thankYouLoc; return false; }); });

 

No need to tag me though, if it's a new post I'll see it.

2 replies

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
April 29, 2020
MktoForms2.whenReady(function(form){ form.onSuccess(function(submittedValues,serverThankYouURL){ var appendValues = { name : submittedValues.FirstName + " " + submittedValues.LastName, email : submittedValues.Email }; /* -- NO NEED TO TOUCH BELOW THIS LINE -- */ var thankYouLoc = document.createElement("a"); thankYouLoc.href = serverThankYouURL; thankYouLoc.search += Object.keys(appendValues).reduce(function(acc,key){ acc += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(appendValues[key]); return acc; }, ""); document.location = thankYouLoc; return false; }); });

 

No need to tag me though, if it's a new post I'll see it.

Stephanie_Berr2
New Participant
April 29, 2020

Thank you @SanfordWhiteman .

 

Now if I want to throw in a variable from a hidden field in the form between the thank you page url and before the appended values?

 

example/meeting/hiddenfield?name=first%20last&email=john@email.com

SanfordWhiteman
New Participant
April 29, 2020

You can add any fields you want to the appendValues object, using the same syntax I did for Email.

 

The order of unique fields in a query string is extremely unlikely to matter. Yechnically the parameters are ordered (as the query string is split into an ordered list) but it would be extremely fragile if your server actually cared about the order.

Stephanie_Berr2
New Participant
April 29, 2020

@sanfordwhiteman I feel like you're the one who can help me answer this.