but it is not working
new form is using this embeding
<script src=“https://js.hsforms.net/forms/embed/XXX65354.js” defer></script>
<div class=“hs-form-frame” data-region=“na1” data-form-id=“54e33587-38e9-4b35-88c3-b4b1ab2fc117” data-portal-id=“21065354”></div>
Hi @TJovevski,
Thank you for posting to the Community!
I understand that you are trying to add a hidden field to a multi-step form with Javascript.
Tagging in some of our Subject Experts to see if they have any ideas on this one -- Hi @Indra@stefen and @Syeda_Fatima Do any of you all have any experience with adding a hidden field to a multi-step form? If so, can you offer any tips to @TJovevski?
Cassie, Community Manager
In this case, example_field would be the internal name of the hidden field in your HubSpot form, and 12345 is the value that would automatically populate when someone submits the form.
The new form works a bit different. The following code should work in your case:
// --- Edit these 3 values ---
const FORM_ID = '54e33587-38e9-4b35-88c3-b4b1ab2fc117'; // your formId
const FIELDNAME = '0-1/amplitude_device_id'; // exact field "name" from your render
const FIELDVAL = 'New value'; // the value you want to set
// (optional alt key if you also have a plain contact property)
const ALT_FIELDNAME = 'amplitude_device_id';
// Ensure we set the field when the form is fully ready
window.addEventListener('hs-form-event:on-ready', (event) => {
try {
const { formId } = event.detail || {};
if (formId !== FORM_ID) return;
// Get the concrete form instance (Forms V4 API)
const form = window.HubSpotFormsV4 && HubSpotFormsV4.getFormFromEvent(event);
if (!form) return;
// Write to HubSpot's internal state (survives rerenders & submits)
form.setFieldValue(FIELDNAME, FIELDVAL);
if (ALT_FIELDNAME) form.setFieldValue(ALT_FIELDNAME, FIELDVAL);
// Optional: verify what HubSpot will submit
form.getFormFieldValues().then(vals => {
// console.log(vals); // uncomment for debugging
});
} catch (e) {
// console.warn(e); // uncomment for debugging
}
});
// Optional: if your form is multi-step, also re-apply on step navigation
window.addEventListener('hs-form-event:on-interaction:navigate', (event) => {
const { formId } = event.detail || {};
if (formId !== FORM_ID) return;
const form = window.HubSpotFormsV4 && HubSpotFormsV4.getFormFromEvent(event);
if (!form) return;
form.setFieldValue(FIELDNAME, FIELDVAL);
if (ALT_FIELDNAME) form.setFieldValue(ALT_FIELDNAME, FIELDVAL);
});
I also want to mention you the portal ID from your sample code is still visible. I suggest to hide/remove it.