APIs & Integrations

PMc8
Member

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

Hello!

 

I am quite new to HubSpot and I need help with capturing an ID # within the URL of a HS form. Specifically, how can I pull the ID # from a URL into a hidden field on a form?

 

I read that I need to implement a custom script that extracts the ID # from the URL and populates the hidden field with this value.

 

But I do not know how to write a custom script to capture this ID from the URL. I would imagine, I would need to write some JS to do this.

 

To further explain my request I have an example URL below.
https://www.columbiasouthern.edu/info-form?utm_source=MilitaryEdRep&utm_medium=Other&repcode=230&utm...

 

I want/need to capture that leadsourceid # 1844 at the end of the URL into a hidden field.

 

PMc8_0-1715281279487.png

 

 

Can anyone assist me on how to capture this number? Thank you in advance!

0 Upvotes
1 Accepted solution
SteveHTM
Solution
Key Advisor | Partner
Key Advisor | Partner

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

@PMc8 - luckily this is quite a simple thing to capture.

If you can make the query parameter name (as in URL?parametername=myvalue) match the internal name of the form field property, then the hidden field value on the form will be poulated. 

See; https://knowledge.hubspot.com/forms/can-i-auto-populate-form-fields-through-a-query-string

 

If you can't make the parameter name match the internal property name, then it's also possible to do a bit of parsing on the 'last page seen' URL value to extract an arbitrary query property value (this may require some cusom code work depending on complexity) using a workflow and store the captured value in your chosen property.

 

Hope that helps!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature

View solution in original post

5 Replies 5
GAlvarez07
Member

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

@SteveHTM You mentioned the exact issue I am facing- the URL parameter has an uppercase "I" so the internal Hubspot value is not matching. Do you have any example codes I could reference for capturing the 15-digit value after "referrerId"? Or is it something like Excel where you parse "=right("field", 15)?

0 Upvotes
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

@GAlvarez07 - fr my issues with this, I used a Custom code workflow step to be able to invoke a couple of line of Python code that translate the URL string to one that can be stored in the HubSpot property. As mentioned I used that code on the 'last page seen' Contact property after the submit action - so the action is not as immediate or as integrated as if the query string contained the correct internal property name as documented.

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
PMc8
Member

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

@SteveHTMThank you for your quick response! So if I follow you correctly, then I need to make a hidden field property with the same name as the URL parameter name value that I want to capture.

 

The query parameter name that I want to capture is General&leadsourceid.

If I give the hidden field property the same name General&leadsourceid then it should capture the id number?

0 Upvotes
SteveHTM
Key Advisor | Partner
Key Advisor | Partner

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

Yes. Well apart from not using a '&' character in the proposed name, I think it could be that simple. Good luck!

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature
0 Upvotes
SteveHTM
Solution
Key Advisor | Partner
Key Advisor | Partner

How can I pull the ID # from a URL into a hidden field on a HS form

SOLVE

@PMc8 - luckily this is quite a simple thing to capture.

If you can make the query parameter name (as in URL?parametername=myvalue) match the internal name of the form field property, then the hidden field value on the form will be poulated. 

See; https://knowledge.hubspot.com/forms/can-i-auto-populate-form-fields-through-a-query-string

 

If you can't make the parameter name match the internal property name, then it's also possible to do a bit of parsing on the 'last page seen' URL value to extract an arbitrary query property value (this may require some cusom code work depending on complexity) using a workflow and store the captured value in your chosen property.

 

Hope that helps!

 

Steve

Steve Christian

HTM Solutions

https://info.htmsolutions.biz/meetings/stevec2

mobilePhone
+1 6195183009
emailAddress
stevec@htmsolutions.biz
website
www.htmsolutions.biz
address
San Diego, CA
Create Your Own Free Signature