# Form widget

Embed and configure inFlow forms on any website.

## Choose your integration

Open your form’s Connect panel. Choose **Use the inFlow design** for a ready-made widget, **Use my site’s design** for native HTML or React controls, or **Give to an agent** for the guide link and a form-specific brief. Select one placement and copy one example.

## Site-owned forms

Your site can own every label, input, layout, and CSS rule. Read the published definition at GET /api/forms/public/FORM_ID, then send answers from the browser to POST /api/leads with Authorization: Bearer pk_YOUR_KEY. Register the site domain under Settings → Connections → Domains & environments first (including `localhost` if you test locally). This browser path needs no secret key; server actions without a validated Origin are not supported by this endpoint.

Connect generates HTML and React (.jsx) examples for text, email, phone, number, boolean, single-select, multi-select, and composite groups. Examples use the actual published IDs, enforce one-of-group requirements, and show submission progress, success, and server errors. Add your site’s classes. Conditional steps, optional groups with required children, photo selection, submit gates, uploads, booking, other advanced types, and hidden attribution need a custom implementation or the ready-made widget; Connect lists those limits instead of generating an incomplete form.

| Answer | Wire format |
| --- | --- |
| Every response | stepId, stepTitle, type, variant |
| Text / email / phone | textValue: string |
| Number | numberValue: number (zero is valid) |
| Boolean | booleanValue: boolean (false is valid) |
| Single / multiple choice | selectedOptions: [{ id, label }] using published option IDs |
| Composite | compositeValues: responses keyed by the nested field IDs |

```json
{
  "submissionVersion": 2,
  "formId": "FORM_ID",
  "responses": [
    {
      "stepId": "PUBLISHED_EMAIL_STEP_ID",
      "stepTitle": "Email",
      "type": "text",
      "variant": "email",
      "textValue": "visitor@example.com"
    }
  ],
  "source": "website"
}
```

The example above illustrates one text answer; send all required answers for your actual form. For a progressive custom form, send submissionVersion: 2 and keep the returned leadId and continuationToken in memory. Send both on a later POST/PATCH update; the token expires after 24 hours. Older unversioned clients receive an opaque leadId and must pass it back unchanged. A bare lead ID cannot update a lead. Failures include message; display it and allow retry. Server validation remains authoritative. Existing contact extraction uses canonical contact field IDs and email/phone variants, with title-based fallbacks. Verify the contact in Leads when customizing labels.

> **Warning:** Generated code uses the live definition, never draft questions. Publishing changed IDs, types, required fields, or options can require updating custom website code. Keep existing IDs when editing labels; compare the published definition after changes. Redirects, upload workflows, conditional behavior, and funnel analytics are not automatically supplied by a plain JSON submission.

## Hand a form to a coding agent

Share https://api.inflow.build/skill.md for the integration guide. Connect → Give to an agent → Copy agent brief includes the form ID, API address, public key, and published definition URL. The agent should fetch that definition before coding and download canonical React files from the guide, rather than reconstructing them. A public key is safe in browser code; never put temporary ik_ or fa_ credentials there.

## Embedding basics

Drop the inFlow form onto any page with a single snippet. Copy it from the form’s **Connect** panel and paste it where you want the form to appear — no code required. _(Help only)_

The inFlow form widget (`tks-form.js`) runs on any website. Drop a `<script>` tag and a container `<div>`, then call `__tks_form.mount()` with a config object. _(Developer only)_

```html
<!-- Load the toolkit -->
<script
  src="https://api.inflow.build/toolkit.v2.js"
  data-tks-key="pk_..."
  data-tks-environment="your_environment_id"
  async
></script>

<!-- Container for the form -->
<div id="my-form"></div>

<script>
  // Mount the form widget
  window.__tks_form.mount(
    document.getElementById("my-form"),
    {
      key: "pk_...",
      formId: "69cab5fdb70caf8914b5a566",
      mode: "inline",
      baseUrl: "https://api.inflow.build",
    }
  );
</script>
```

_(Developer only)_

If you use React or Next.js, the `<InflowForm>` component handles the script loading and lifecycle for you. The same config keys work in both approaches — the object you would pass to `mount()` becomes the component's props. _(Developer only)_

```tsx
import { InflowForm } from "@/components/embed/InflowForm";

export default function ContactPage() {
  return (
    <InflowForm
      formId="69cab5fdb70caf8914b5a566"
      publicKey="pk_..."
      mode="inline"
    />
  );
}
```

_(Developer only)_

## Pre-filling form fields

`prefill` injects initial values into form fields at mount time. Each field in your form can have a `prefillKey` set in the form builder. When a key in `prefill` matches a field's `prefillKey`, its slugified title, or its internal ID, the value is applied. _(Developer only)_

Common use case: you already know the user's name and email from your app's session. Pass them in so they land on a pre-filled form instead of an empty one. _(Developer only)_

```tsx
<InflowForm
  formId="..."
  publicKey="..."
  prefill={{
    first_name: user.firstName,
    last_name: user.lastName,
    email: user.email,
    company: orgName,
  }}
/>
```

_(Developer only)_

## Injecting contact info

When a form is submitted, the inFlow API runs a heuristic to extract a contact name and email from the form's step titles and variants. If your fields aren't named in a way the heuristic recognises — for example, they use custom titles or non-standard variants — the lead can appear as **"Unknown"** in the CRM. _(Developer only)_

The `contact` config key solves this by injecting name, email, and phone **directly into the lead submission payload**, bypassing the heuristic entirely. The CRM always shows the name you specify. _(Developer only)_

```tsx
<InflowForm
  formId="..."
  publicKey="..."
  prefill={{ first_name: "Alex", email: "alex@example.com" }}
  contact={{
    name: "Alex Smyntyna",
    email: "alex@example.com",
    phone: "+15551234567",   // optional
  }}
/>
```

_(Developer only)_

> **Note:** _(Developer only)_ **When the lead arrives:** the server sets `lead.contact` from this object immediately. The response-based extraction still runs and can *add* missing fields (e.g. a phone number extracted from a phone step), but it won't *replace* a name or email you already supplied unless a form response explicitly provides a different value.

## Hidden fields & metadata

The form builder lets you configure hidden fields for UTM params, referrer, page URL, and custom URL query keys. But if you need to pass dynamic values that aren't from the URL — like an org ID, a user ID, or a plan tier — use `hidden`. _(Developer only)_

It merges key/value pairs into the lead submission's `hiddenFields` after URL params and form-configured defaults. _(Developer only)_

```tsx
<InflowForm
  formId="..."
  publicKey="..."
  hidden={{
    org_id: "67f1a2b3c4d5e6f7a8b9c0d1",
    plan: "enterprise",
    signup_channel: "direct",
  }}
/>
```

_(Developer only)_

> **Note:** _(Developer only)_ Hidden field keys must match a hidden field configured in the form builder (with `source: "custom"`). Values from the URL take priority over form defaults, which take priority over `config.hidden`.

## Priority rules

When the same information could come from multiple sources, the widget follows these rules. For `prefill` vs URL params, **URL query params win**: if your page URL is `?email=url@test.com` and you pass `prefill: { email: "config@test.com" }`, the form shows the URL value. _(Developer only)_

For each hidden field key, the first non-null value wins, in this order: _(Developer only)_

1. **URL query params** — matches the hidden field's key
2. **Form-configured defaults** — from the form builder
3. **config.hidden** — programmatic override

_(Developer only)_

## Full config reference

Every key accepted by the form widget's `mount()` config object: _(Developer only)_

| Key | Type | Description |
| --- | --- | --- |
| key | string | Public key (pk_…) — required |
| formId | string | Form ID — required |
| mode | string | "inline" \| "popup" \| "fullpage" (default "inline") |
| baseUrl | string | inFlow API origin (default "https://api.inflow.build") |
| prefill | Record<string, string> | Field values keyed by prefillKey, title slug, or step ID |
| contact | { name?, email?, phone? } | Injected directly into the lead's contact |
| hidden | Record<string, string> | Metadata merged into hiddenFields |
| draft | object \| null | Form definition for preview mode (dashboard only) |
| readOnly | boolean | Disables lead submission (preview mode) |
| editable | boolean | Enables inline editing affordances |
| styles | object | CSS custom property overrides for theming |

_(Developer only)_
