So basically, we’ve built custom private pages for our client’s customers. The thing is that there are many customers groups/segments and we created one private page per group.
So, in order to join these pages, the users must fill out a form inside HubSpot and one of the form fields is called “Security Token”, a single-line text field.
Depending on the group they belong to, the customers will enter a different “Security Token”, with this “token”, we identify the segment where they belong to.
So, for internal purposes, we need to pass the “Security Token” field value into a string parameter in the URL of the page that they’re redirected.
An example:
The user fills out the form (COS Page and HubSpot form), and its token is “TOKEN101”
Form is submitted and it’s redirected to the desination page.
And you can add as many parameters as you'd like. Notice that if it's a company or deal property you'll have to change "contact.email" for "company.name" for instance or "deal.deal_amount".
Heya. If anyone would still need help, then I solved this by a simple 2step script.
On the first page you need to take that email and encode it as UTM, and on the 2nd page (2nd step if you will) you need to that that UTM, decode it, and input it into the field.
Step 1:
<script type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js" charset="utf-8"></script><script> // Function to redirect with UTM parameter function redirectToPageWithEmail(email) { var baseUrl = "https://dev.aidigital.org/page-2"; var newUrl = baseUrl + "?utm_email=" + encodeURIComponent(email); window.location.href = newUrl; }
// HubSpot form creation and submission handling hbspt.forms.create({ region: "na1", portalId: "22130692", formId: "626e67c3-0651-4e57-be9d-bd6d5505b74d", onFormSubmit: function($form) { // Capture the email from the form var email = $form.find('input[name="email"]').val(); console.log(email); // Logging the email for debugging
// Add a delay before redirecting setTimeout(function() { // Redirect to the specific URL with the email as a UTM parameter redirectToPageWithEmail(email); }, 2000); // 2-second delay } }); </script>
Step 2:
<script defer> // Initialize timeout and interval variables var timeout = 10000; // 10 seconds var interval = 500; // 500 milliseconds
// Function to populate email field function populateEmailField() { var urlParams = new URLSearchParams(window.location.search); var email = urlParams.get('utm_email'); var decodedEmail = decodeURIComponent(email); var emailField = document.getElementById('email-b54fdc79-efe6-451f-8793-1953e2cdc233');
// Check for the email field at intervals var checkInterval = setInterval(function() { if (populateEmailField() || Date.now() - startTime > timeout) { clearInterval(checkInterval); } }, interval); </script>
Bear in mind:
1) Form ID and portal ID are dummy (they are to my developer account), so replace them with form and portal IDs of your own.
2) Redirect URL (the URL where it says Redirect URL) is to my dummy agency (its actually real agency, but these web sites are with dummy content mostly - no time to fill it in). So edit it to go to page you need it to go to.
3) The best is to set the form as raw HTML, otherway you might be able to edit its contents via script (it's very unlikely, given the not-raw form you can't even style with CSS).
Still have trouble? Rate my answer, and don't forget I do this for a living (I can do it for you as well).
Feb 9, 202110:56 PM - edited Feb 10, 202112:17 AM
Participant
Pass field value to URL parameter
SOLVE
Hi @Konistand, I don't suppose you got this to work?
I have the exact same issue. `contact.firstname` works if an existing contact is submitting the form and the form fields are pre-populated, but if it's a new user submitting the form, the querystring value is empty (or the fallback is used when using `personalization_token`). It doesn't matter what they enter, it seems `contact.firstname` isn't set...
Had to go down the embed and use Javascript to edit the redirectUrl path as per here.
Yeah, I have the same problem. Unfortunately the form is my in my foot, and I don't have access to embed it based the 'hatch' theme.
HS does seem to pass some other query variables like __hsfp and _hscc, etc. I wonder if I could use those server side to pull data from the form submission? Oh wait, it looks like the forms API does not allow you to pull anything specific.
Hi @Konistand what if you delete the "valeur_par_default" from the name field? Sorry I ran out of ideas. It works for me but I can't see what is not working in your case.
I've tried multiple ways (including what you are suggeting) but I always get the same error that the value is not displayed:
- Test 1: https://rcos.be/connexion?create_account=1&firstname= {{ personalization_token("contact.firstname", "Add here default value") }} --> this test return URL with firstname = Add here default value; which is not what I want
Hi @Konistand , from what I see in your recording, have you checked that the ID of the field "prenom" is "firstname"? If it returns"Add here default value" or is empty in the second case, it looks like it's working the passing of information, but not the connection with the property value of the form.
And you can add as many parameters as you'd like. Notice that if it's a company or deal property you'll have to change "contact.email" for "company.name" for instance or "deal.deal_amount".
Regarding the original question; if you were to use a custom HTML form and the forms API, you could redirect the visitor to any URL with whatever query parameters you’d like. You could also customize the form embed code to dynamically change the redirectUrl to include query parameters, as previously discussed on the forums:
redirect to your desired page and attach whatever contact property you desire via query parameters. http://redirect-address.com/the-page?token={{contact.your_internal_property_name}}
After you click save, you can see your link when you hover over test link
I like kudos almost as much as cake – a close second.
As I can see, the only problem with this solution is that there is a certain delay before the parameters appear in the URL. Do you have any suggestions on this? How can I work around this problem?