Submit custom ID via form plus redirect

I’m trying to pass a value through a form field via the embed code, along with doing a custom redirect. I see the documentation says to use OnFormSubmitted for the redirect, but this seems to work fine, not sure if it’s needed:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js">
</script>
<script> 
hbspt.forms.create
({ region: "na1",
portalId: "XXXXXX",
formId: "XXXXXX-XXXXXX-XXXXXX-XXXXXX",
redirectUrl: "https://www.redirectgoeshere.com/"
}); 
</script>

But I’m stuck on passing the value - I have only found threads discussing passing values based on form inputs which isn’t necessary for my case. The field is called recent_asset_id.

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/embed/v2.js">
</script>
<script> 
hbspt.forms.create
({ region: "na1",
portalId: "XXXXXX",
formId: "XXXXXX-XXXXXX-XXXXXX-XXXXXX",
redirectUrl: "https://www.redirectgoeshere.com/",
recent_asset_id: "test"
}); 
</script>

Any help appreciated

Hi @evelliQM ,

If you add the ‘recent_asset_id’ property as an hidden input to the form, you should be able to do this:

<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js?pre=1"></script>
<script>
 hbspt.forms.create({
 region: "na1",
 portalId: "XXXXXX",
 formId: "XXXXXX-XXXXXX-XXXXXX-XXXXXX",
 redirectUrl: "https://www.redirectgoeshere.com/",
 onFormSubmit: ($form) => {
 const assetIdInput = document.querySelector('[name="recent_asset_id"]');
 if (assetIdInput) {
 assetIdInput.value = "test";
 assetIdInput.dispatchEvent(new Event('input', { bubbles: true }));
 }
 },
 });
</script>