Skip to main content
Level 2
Jan 20, 2022 11:51 AM UTC
Solved

Form follow up URL using a form field value

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

SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Jan 20, 2022 5:34 PM UTC

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.

2 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Jan 20, 2022 5:34 PM UTC

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.

Translate
geordniAuthor
Level 2
Jan 21, 2022 10:29 AM UTC

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.

Translate