TeamDesk Knowledge Base & Support

   Home      FAQ      Forum      Idea Exchange      Ask a Question      My Stuff      Help   
  
Dynamic Redirect URL web-to-record form
Currently when creating a web-to-record form using html/javascript, you can display a message or redirect to URL.

It would be great if the redirect URL could be dynamic (as the custom URL is in the navigate option) so that data such as record ID could be passed to the directed webpage via the URL.
ID
1220
Category
TeamDesk
Author

Adrian Thompson
Date Created
8/23/2018 8:03:43 AM
Date Updated
11/17/2022 7:32:04 PM
Status
New Idea
Score
100
Promoted By
Nick KempPierreAndrew@mytangowood.com
Ingrid ZambranoMatt HillAndrew Winters
basenineScott MillerPatricio Bustos
Adrian Thompson
Comments
Matt Hill 10/5/2021 5:07:40 PM
100% support this idea.
basenine 11/6/2022 6:39:24 PM
Again, I could really use this as a function 🙂

Especially useful for creating new users with a redirect to 'their' specific registration page.
It's my understanding that the registration URL sent via email contains a GUID specific to a user.
My current 'workaround' only completes ½ the desired outcome.
I set up a redirect with 2 choices; an option to sign-in if already a member or to register if not; the missing piece is the GUID for a new user.
basenine 11/10/2022 3:55:24 AM
If there were some JavaScript that could replace the inbuilt redirect link (which is used in the ‘Submit’ process) with one which is constructed whilst the W2R is being completed, we’d have a solution
😊
Nick Kemp 11/17/2022 6:32:12 AM
I pass vars using html data- attributes (on hidden elements)/url Params and build the w2r script loading code on the client. Did it for another reason, but could be adapted. Will have a crack tomorrow as custom redirect would be nice. Drop me a message , always keen to connect with other users nick@bridgepoint.co.nz 😊
basenine 11/17/2022 6:42:42 AM
Thanks Nick
Look forward to seeing what you come up with 👍
Best regards
Brett
Nick Kemp 11/17/2022 6:39:23 PM
My solution, while not pretty, works. You have two options, pass the redirect url via url parameter or, via a hidden HTML element. The former is simpler,
but the later is probably better if you are redirecting to long urls with user GUIDs etc. That's what I'm going to run with today.

In essence, the challenge is that embed.js is loaded async and we have no way of knowing when it's done. So, we monitor the DOM for changes which will allow us to catch changes embed.js makes once loaded. We can then read in the hidden vars and do stuff!

1. Create an XHTML-Formula field (I call mine HTML:Variables) for your webform. Formula:
<span id="formVars" data-redirect="<%[Your redirect URL field or formula here]%>" hidden="hidden"></span>

2. Add [HTML:Variables] to the form and set it to visible on edit.

3. Edit the web-to-record settings for your table and select message, not redirect. In the message but a string that will tell our script that the form has been submitted.
In this example I have used "!redirect", but because the user will see this for a moment, try something nicer like "Redirecting...". Just ensure
that the text doesn't appear on your form anywhere else. If you do your form will just break for everyone.

4. Add the following to he <head> section of the HTML page where you embed your form. DO NOT put this block in the body.
<script>
var formVars;
var redirectString = "!redirect"; // Set this to the conent of

var observer = new MutationObserver((mutations) => {
// Attempt to refence the elenements we need (only if we don't have them yet)
if (formVars == undefined) formVars = document.getElementById('formVars');

// If we have our formVars we can do stuff
if(formVars?.dataset !== undefined) {

// If we have the redirect directive, redirect
if(document.body.innerHTML.indexOf(redirectString) !== -1){
if(formVars.dataset.redirect !== undefined) {
window.location.href = formVars.dataset.redirect;
}
}
}
});
</script>

5. Add the following after the opening <body> tag:
<script>
observer.observe(document.body, {
characterDataOldValue: true,
subtree: true,
childList: true,
characterData: true
});
</script>

Thats it team, enjoy your new forms :)

Nick
bridgepoint.nz

basenine 11/17/2022 7:32:04 PM
Truly wonderful Nick.

Thank you for this...I'll let you know how I go.

Enjoy your weekend 🙂
best regards
Brett
Feedback
 
Back to Search Results