# Set Form Field Value with HubL

**URL:** <https://community.hubspot.com/t/set-form-field-value-with-hubl/24407>\
**Category:** CMS Development\
**Tags:** hubdb, forms\
**Created:** [August 20, 2020, 2:08am UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407 "2020-08-20T02:08:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jon\_Sasala](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jon_sasala/32/96281_2.png) [@Jon\_Sasala](https://community.hubspot.com/u/Jon_Sasala)\
**Post date:** [August 20, 2020, 2:08am UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407/1 "2020-08-20T02:08:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [August 20, 2020, 2:02pm UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407/2 "2020-08-20T14:02:31Z")

</div>

[@Jon\_Sasala](https://community.hubspot.com/t5/user/viewprofilepage/user-id/53414) 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](http://example.com/contact?email=john@example.com)_ — this will pre-populate the email field with [john@example.com](mailto:john@example.com).

**Javascript&colon;**

After the form loads on the page, use a script to pre-populate a field like so:

```lia-code-sample
window.addEventListener('message', event => {
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
 $('input[name="email"]').val("john@example.com");
 }
});

```

---

<div class="post-metadata">

**Author:** ![Jon\_Sasala](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jon_sasala/32/96281_2.png) [@Jon\_Sasala](https://community.hubspot.com/u/Jon_Sasala)\
**Post date:** [August 20, 2020, 2:49pm UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407/3 "2020-08-20T14:49:39Z")

</div>

Thanks for the solutions, Stephen.

I am trying to avoid the URL UTM route, so we will explore Javascript. In your experience, will HubL tokens populate javascript properly? For example:

```lia-code-sample
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
 $('input[name="listing_id"]').val("{{dynamic_page_hubdb_row.hs_id}}");
 }
});

```

Thank again!

---

<div class="post-metadata">

**Author:** ![stefen](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/stefen/32/29274_2.png) [@stefen](https://community.hubspot.com/u/stefen)\
**Post date:** [August 20, 2020, 2:51pm UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407/4 "2020-08-20T14:51:18Z")

</div>

[@Jon\_Sasala](https://community.hubspot.com/t5/user/viewprofilepage/user-id/53414) 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.

---

<div class="post-metadata">

**Author:** ![DBoroi5](https://avatars.discourse-cdn.com/v4/letter/d/ed8c4c/32.png) [@DBoroi5](https://community.hubspot.com/u/DBoroi5)\
**Post date:** [January 10, 2023, 4:32pm UTC](https://community.hubspot.com/t/set-form-field-value-with-hubl/24407/5 "2023-01-10T16:32:24Z")

</div>

@stef1 [@Jon\_Sasala](https://community.hubspot.com/t5/user/viewprofilepage/user-id/53414) I tried this and not getting property to populate.

Inserted this into dynamic page with form Footer:

```lia-code-sample
<!-- start Main.js Do Not Remove -->
<script src='{{ get_asset_url('/EBIS Power/Event Form.js') }}'></script>
<!---End Main.js-->

```

JS file contained:

```lia-code-sample
 if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
 $('input[name="webinar_id"]').val("{{dynamic_page_hubdb_row.webinar_id}}");
 }
});

```

Form contained hidden unformatted number field webinar\_id

HubDB table included column webinar\_id
