Form follow up URL using a form field value | Community
Skip to main content
Level 2
January 20, 2022
Solved

Form follow up URL using a form field value

  • January 20, 2022
  • 1 reply
  • 2464 views

I am using a form to capture basic details such as name, email, website. I'd like to use the input from the website field + a predefined set of characters as a follow-up external URL.

 

For example website field is: www.example.com 

Pre-defined characters are: /123XYZ

The follow-up URL would be  example.com/123XYZ

 

As form URLs only allow text my.tokens and nested tokens are not possible to use, is there any other way I can achieve the above? 

 

P.S. I have made sure the website field only captures valid websites such as example.com or www.example.com

Best answer by SanfordWhiteman

P.S. I have made sure the website field only captures valid websites such as example.com or www.example.com

Not sure what you mean by “valid” here, but if the field Website always contains a hostname and you want to swap that hostname into the Thank You URL:

MktoForms2.whenReady(function(mktoForm){ mktoForm.onSuccess(function(submittedValues,baseThankYouURL){ let thankYouLoc = document.createElement("a"); thankYouLoc.href = baseThankYouURL; thankYouLoc.hostname = submittedValues["Website"]; document.location = thankYouLoc; return false; }); });

 

You would set the Thank You URL in form editor to a placeholder like https://www.example.com/123456. Then at runtime the www.example.com  is replaced by whatever the Website value was.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
January 20, 2022

P.S. I have made sure the website field only captures valid websites such as example.com or www.example.com

Not sure what you mean by “valid” here, but if the field Website always contains a hostname and you want to swap that hostname into the Thank You URL:

MktoForms2.whenReady(function(mktoForm){ mktoForm.onSuccess(function(submittedValues,baseThankYouURL){ let thankYouLoc = document.createElement("a"); thankYouLoc.href = baseThankYouURL; thankYouLoc.hostname = submittedValues["Website"]; document.location = thankYouLoc; return false; }); });

 

You would set the Thank You URL in form editor to a placeholder like https://www.example.com/123456. Then at runtime the www.example.com  is replaced by whatever the Website value was.

geordniAuthor
Level 2
January 21, 2022

Thank you so much, this worked!

By "valid" website I meant only example.com or https://example.com are accepted, not simply example or test.