Passing Form Data to a Marketing Agent

Last updated: August 11, 2026

Pass selected form values to Docket before opening the widget so the agent can continue the visitor's journey without asking for the same information again.

Before You Begin

  • Install the Docket widget script on the page.

  • Configure the corresponding fields under Agent > Dynamic Context Ingestion.

  • Decide which submitted values the agent actually needs.

  • Do not send passwords, tokens, payment details, or other sensitive form values.

Configure the Variables

  1. Open the agent's Agent tab.

  2. Expand Dynamic Context Ingestion.

  3. Enable the feature and add each form field the agent should use.

  4. Give each variable a clear description.

Pass Selected Form Fields

Map the fields explicitly. Do not pass the complete FormData object because file inputs and unsupported values can cause validation to fail.

<form id="demo-request">
  <input name="name" autocomplete="name" required />
  <input name="email" type="email" autocomplete="email" required />
  <input name="company" autocomplete="organization" />
  <button type="submit">Talk to Sales</button>
</form>

<script>
  document.getElementById("demo-request").addEventListener("submit", async (event) => {
    event.preventDefault();

    if (!window.AISeller?.setContext || !window.AISeller?.showAndConnect) {
      console.warn("The Docket widget is not ready.");
      return;
    }

    const form = new FormData(event.currentTarget);
    const result = await window.AISeller.setContext({
      name: String(form.get("name") || ""),
      email: String(form.get("email") || ""),
      company: String(form.get("company") || "")
    });

    if (!result.success) {
      console.warn("Docket context was not stored:", result.message);
      return;
    }

    window.AISeller.showAndConnect();
  });
</script>

The widget accepts flat values that are strings, numbers, booleans, or null. Nested objects, arrays, files, functions, dates, and undefined values are rejected.

Reset Context When Identity Changes

Call resetContext() when a visitor logs out or when another person may use the same browser session.

await window.AISeller.resetContext();

Verify the Form Flow

  1. Open the page in a private browser window.

  2. Submit the form with documentation-only values.

  3. Confirm setContext() returns success: true.

  4. Confirm the widget opens and starts the conversation.

  5. Verify the agent uses the submitted values according to the configured variable descriptions.

  6. Reset context and confirm a new conversation does not reuse the previous visitor's values.

Troubleshooting

Problem

What to check

The form submits but the widget does not open

Confirm window.AISeller.showAndConnect exists and call it only after setContext() succeeds.

setContext() returns success: false

Read result.message and remove unsupported values such as files, arrays, or nested objects.

The agent ignores a field

Confirm the JavaScript key matches a configured Dynamic Context variable.

The page navigates away before context is stored

Call event.preventDefault() and await setContext() before continuing the normal form workflow.

Another visitor's values appear

Call resetContext() when identity changes or before storing the next visitor's data.

Related Articles