Pass field value to URL parameter

SOLVE
BorjaInbound
Participant

Hello!

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:

  1. The user fills out the form (COS Page and HubSpot form), and its token is “TOKEN101”
  2. Form is submitted and it’s redirected to the desination page.
  3. The destination page URL should be “www.example.com/destination-page?token=token101

Is there any way to achieve this? Maybe using Forms API?

Thanks in advance for your time :slight_smile:

1 Accepted solution

Accepted Solutions
Oscar1
Solution
Top Contributor

We needed to pre-fill some hidden fields from a form based on a URL from a CTA we send in an e-mail. This is the way that works for us:

 

https://example.com?email={{ personalization_token("contact.email", "Add here default value") }}

 

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".

 

Hope that works for you.

View solution in original post

19 Replies 19
Samantha_Alford
Top Contributor

Hey @Borja_InboundLead,

did you end up working out how to do this? I have the same challenge.

Thanks in advance,
Sam


Samantha Alford
Did my post solve the issue? If so, please accept it as a solution!
Trevor_Hatfield
Member

Would love to know if there is a solution to this yet?

0 Upvotes
redfoxius
Member

According to this API endpoint documentation you must use content-type:application/x-www-form-urlencoded, so you ll lost your redirect link’s get parameters. But you can analyze your token before cURL call and/or use some service link like example.com/token/<your_token> with redirect to example.com/destination-page?token=token101

0 Upvotes
Derek_Gervais
HubSpot Employee

Hi all,

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:

0 Upvotes
John
Top Contributor | Platinum Partner

If the form is on a COS page, then i think it is easier than you think (you won't even have to do anything api related)

  1. Go to edit the form module

  2. Even if you are going to an internal page, click redirect to external URL

  3. 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.

ElsaB
Participant | Diamond Partner

Hi everybody,

 

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?

Thanks a lot

 

0 Upvotes
Oscar1
Solution
Top Contributor

We needed to pre-fill some hidden fields from a form based on a URL from a CTA we send in an e-mail. This is the way that works for us:

 

https://example.com?email={{ personalization_token("contact.email", "Add here default value") }}

 

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".

 

Hope that works for you.

View solution in original post

Sheamus
Member

This doesn't seem to work for me either. In the Options section for my form, I have the redirect set to an external link:

https://app.mysite.com/signup/?email={{ personalization_token("contact.email", "default") }}

 

My application then reads the query variable and processes it. But when I fill out the form, I endup being redirected to this url:

https://app.mysite.com/signup?email={{%20personalization_token(%22contact.email%22,%20%22default%22)%20}}&__hsfp=2275750999&__hssc=251652889.1.1619120724980&__hstc=251652889.42bb2e0b19539640357b860107ae97c6.1619120724980.1619120724980.1619120724980.1

 

Which of course is not what I want. the URL should be https://app.mysite.com/signup?email=doug@gmail.com&_hsfp=....

0 Upvotes
Konistand
Member

Hello,

Thanks for the help. I'm still struggling to get it working. I used the following code:

https://mywebsite.be/connexion?create_account=1?method=post&firstname={{Contact.firstname}}

 

This is my URL at the moment they click on submit form (from hubspot). But the data is always empty even if the form is filled in.

 

does someone also have experienced this?

Thanks,

0 Upvotes
Oscar1
Top Contributor

Hi @Konistand , why do you have two "?" in your URL?

 

Have you tried it this way to pass the first name value?:
https://mywebsite.be/connexion?firstname={{ personalization_token("contact.firstname", "Add here default value") }}

 

Konistand
Member

Hi @Oscar1 ,

 

Thanks for helping out; I've been spending hours on that already :).

So what I want to achieve in the end is an URL which looks like this: https://rcos.be/connexion?create_account=1&firstname=Nico

where firstname is coming from the form.

 

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

- Test 2: https://rcos.be/connexion?create_account=1&firstname= {{Contact.firstname}} --> this test returns firstname = <empty>

 

You can see here more information if you want: https://www.screencast.com/t/GfvrVQf14

 

Thank you VERY much.

Nicolas.

 

0 Upvotes
Oscar1
Top Contributor

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. 

Konistand
Member

Hi @Oscar1 ,

 

Yes the ID field of "prenom" is correctly the first name. This is what you can see at the beginning of the screencast.

Look here: https://www.screencast.com/t/TFkc4uZyUJP

 

Do you have any other idea 🙂 ?

Thanks,

Nicolas.

0 Upvotes
Konistand
Member

Hi @Oscar1 , let me know if you need to get more data to help out 🙂

0 Upvotes
Oscar1
Top Contributor

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.

0 Upvotes
Konistand
Member

Hi @Oscar1 , thanks for trying to help :).

I tried the following : https://rcos.be/connexion?create_account=1&firstname={{personalization_token("contact.firstname")}} and it gives me the following result: https://rcos.be/connexion?create_account=1&firstname=CONTACT.FIRSTNAME

 

I find it quite interesting because:

1. It puts it in capital letters so something is happening

2. If I make a typo mistake (e.g. contact.firstnamee); it's doesn't do it

 

Can you please share with me what you have written to make it work?

Thanks,

Nicolas.

0 Upvotes
bradhardinge
Participant

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.

0 Upvotes
Sheamus
Member

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.

0 Upvotes
andriigo
Contributor

Hm, doesn't work for me...

I tried this:

https://app.website.com?url={{contact.website}}

https://app.website.com?url={{personalization_token("contact.website”, "Add here default value")}}

 

I'm using HubSpot form embedded on non-HS landing page.

Any help?

0 Upvotes