Passing HubSpot Form Submissions to Docket
Last updated: October 26, 2026
HubSpot forms and the Docket widget can sit on the same page and hand off to each other. Once someone submits the form, you read the values HubSpot collected and pass them to the agent, so the conversation starts with their name and company already known.
Which code you write depends on which kind of form you have. HubSpot's updated forms editor emits browser events; older forms post a window message instead. Check which one you are using before you start, because the two APIs are not interchangeable.
What do you need before you start?
The HubSpot form and the Docket widget installed on the same page.
The HubSpot tracking code installed on that page. HubSpot requires it for forms embedded outside HubSpot.
A variable configured on the agent for each field you plan to pass. See Setting Up Dynamic Context Ingestion.
Your website domain added to HubSpot as an additional site domain. This one is easy to miss and is covered next.
Why do HubSpot submissions land in spam?
HubSpot filters submissions that come from a domain it does not recognise. If your site is not registered, the form appears to work, the visitor sees a success message, and the submission is quietly filed under spam with the reason "Unregistered Site Domain".
Add your domain in HubSpot before you test anything:
In HubSpot, open the settings icon, then go to Tracking & Analytics and Tracking Code.
Open the Advanced Tracking tab.
Under Additional site domains, select Add domain and enter the domain hosting the form.
Review your existing spam submissions and release any genuine ones that were already filtered.
Adding a top-level domain covers its subdomains. Adding www.example.com covers only that host. If your CMS submits forms from a helper or iframe domain, add that domain too.
How do you pass values from an updated HubSpot form?
Updated forms emit hs-form-event:on-submission:success on window. Use HubSpotFormsV4.getFormFromEvent() to get the form instance, then read the fields you need.
window.addEventListener("hs-form-event:on-submission:success", async (event) => {
if (!window.HubSpotFormsV4 || !window.AISeller?.setContext) {
return;
}
const form = window.HubSpotFormsV4.getFormFromEvent(event);
const [firstName, email, company] = await Promise.all([
form.getFieldValue("0-1/firstname"),
form.getFieldValue("0-1/email"),
form.getFieldValue("0-1/company")
]);
const result = await window.AISeller.setContext({
name: String(firstName || ""),
email: String(email || ""),
company: String(company || "")
});
if (result.success) {
window.AISeller.showAndConnect();
} else {
console.warn(result.message);
}
});The 0-1/ prefix is HubSpot's identifier for the Contact object, so 0-1/firstname means the contact's first name. Fields stored on the company object use 0-2/. Field names vary between portals, so check the names in your own form rather than copying these.
getFieldValue() is asynchronous, which is why the example awaits it. A multi-checkbox field returns an array, so join or pick a value before passing it on.
How do you pass values from a legacy HubSpot form?
Legacy forms post a window message. Listen for hsFormCallback with the event name onFormSubmitted, which fires after HubSpot has saved the submission.
window.addEventListener("message", async (event) => {
const data = event.data;
if (data?.type !== "hsFormCallback" || data.eventName !== "onFormSubmitted") {
return;
}
if (!window.AISeller?.setContext || !window.AISeller?.showAndConnect) {
return;
}
const fields = data.data?.submissionValues || {};
const result = await window.AISeller.setContext({
name: String(fields.firstname || ""),
email: String(fields.email || ""),
company: String(fields.company || "")
});
if (result.success) {
window.AISeller.showAndConnect();
} else {
console.warn(result.message);
}
});Note the difference in field names. Legacy submissionValues keys are plain, such as email, with no 0-1/ prefix. If you support both form types, read each one with its own code rather than sharing a single parser.
Use onFormSubmitted rather than onFormSubmit. The earlier event fires before HubSpot has stored the submission.
What happens if the form redirects?
HubSpot form events do not hold up a configured redirect. If the form sends visitors to a thank-you page, the widget may not have time to open.
Either run the Docket code on the destination page, or remove the redirect so the conversation can start where the form is.
How do you check that it works?
Open the page in a private browser window.
Submit the HubSpot form with test values.
Confirm the success event fires for your form type.
Confirm
setContext()returnssuccess: true.Confirm the widget opens and the conversation starts.
In HubSpot, confirm the submission appears as a normal submission and not as spam.
Frequently asked questions
My listener never runs. What should I check first?
Confirm which form generation you have. Updated forms emit hs-form-event:on-submission:success; legacy forms post hsFormCallback. Listening for the wrong one is the most common cause.
The form works but nothing appears in HubSpot. Why?
The submission was probably filtered as spam because the domain is not registered. Add it under Advanced Tracking as described above, then release the filtered submissions.
My field values come back empty.
The field identifiers do not match your form. Inspect the form's actual field names in HubSpot and use those, including the 0-1/ prefix on updated forms.
setContext() returns success: false after a HubSpot submission.
A HubSpot value is not a simple type, most often a multi-checkbox array. Convert it to a string, number, boolean or null first.
I have two HubSpot forms on one page and both trigger the handler.
Check the form and instance identifiers on the event and act only on the one you want.
Does this write anything back to the HubSpot contact record?
Not by itself. This passes values to the agent for the conversation. For syncing Docket activity into HubSpot, see Setting up the HubSpot CRM for Docket Marketing Agent.