Hello all. I am looking to set a hidden form value based on data from the page where it is submitted. Is there a way with HubL you can set hidden values that populate form fields?
This would allow us to include page information in the actual form submission. For example, if we have dynamically generated HubDB pages, and one form that appears on all of them, I would like the page ID to be included in the form submission.
Any advice is appreciated. Thanks for your help.
Jon Sasala (He / Him) President • Hypha HubSpot Development
@Jon_Sasala if you have control of the form's markup, you can easily include whatever HubL variable as the value of the input. However, if you're using a HubSpot form embed, you can pre-populate fields using 2 options: url query parameters or javascript on page load.
Query Parameters:
use a link from a previous page that includes query paremeters e.g.: example.com/contact?email=john@example.com — this will pre-populate the email field with john@example.com.
Javascript:
After the form loads on the page, use a script to pre-populate a field like so:
@Jon_Sasala if you have control of the form's markup, you can easily include whatever HubL variable as the value of the input. However, if you're using a HubSpot form embed, you can pre-populate fields using 2 options: url query parameters or javascript on page load.
Query Parameters:
use a link from a previous page that includes query paremeters e.g.: example.com/contact?email=john@example.com — this will pre-populate the email field with john@example.com.
Javascript:
After the form loads on the page, use a script to pre-populate a field like so:
@Jon_Sasala yes, I've done that before without any issues. Just have to make sure to use inline scripts in a HubL module area or directly in the HubL html template.