# Your form on your own site

> Put a Zanfia signup form on any website (WordPress, Webflow, plain HTML) with your own markup and styling: the native form contract, the script, the payload and the error codes.

Source: https://zanfia.com/help/developer-api/forms-embed · Updated: 2026-11-04 · Id: developer-api.forms-embed

A Zanfia signup form does not have to live on a Zanfia page or in an iframe. The same native form that Zanfia pages use works on any site you host yourself: you write the HTML and the styles, one script wires the form to your workspace, and the tags, opt-in mode and thank-you redirect come from the form's settings.

### 1. Get the snippet

The quickest way is the CLI, which prints ready-made markup for a form:

```bash
zanfia forms snippet <formId> --lang pl --first-name
```

Or write it by hand. The minimum is a form tagged with your workspace id and the form id, an e-mail field, a submit button and the script:

```html
<form data-zanfia-form="{workspaceId}/{formId}">
  <label>E-mail<br /><input name="email" type="email" required autocomplete="email" /></label>
  <input name="website" type="text" tabindex="-1" autocomplete="off" aria-hidden="true" style="position:absolute;left:-9999px;opacity:0" />
  <button type="submit">Sign me up</button>
  <div data-zanfia-success hidden>Thank you! Check your inbox to confirm.</div>
  <div data-zanfia-error hidden>Something went wrong. Please try again.</div>
</form>
<script src="https://zanfia.co/zanfia-page-forms.js" defer></script>
```

Your workspace id comes from `GET /workspace` (or `zanfia workspace get`), the form id from `GET /forms` (or `zanfia forms list`).

### 2. The contract

The script looks for every `form[data-zanfia-form]` on the page and takes over its submit. Everything else about the form is yours: tags, classes, layout, CSS.

| Element                                   | Required | What it does                                                                                                                       |
| ----------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `data-zanfia-form="{workspaceId}/{formId}"` | yes      | Which form receives the signup.                                                                                                    |
| `input[name="email"]`                     | yes      | The address. The form does nothing when it is empty.                                                                               |
| `input[name="firstName"]`                 | no       | Stored on the client.                                                                                                              |
| `input[name="trackingConsent"]` (checkbox) | no       | Engagement-tracking consent. Only a ticked box grants it.                                                                          |
| `name="custom.<key>"` (input, select, checkbox, hidden) | no | A custom contact field the form asks for (see 6). Any other key is ignored.                                         |
| `input[name="website"]`                   | no       | Honeypot. Keep it visually hidden; a filled value means a bot and nothing is sent.                                                 |
| `button[type="submit"]`                   | yes      | Gets `aria-busy="true"` and is disabled while the request runs.                                                                    |
| `[data-zanfia-success]`                   | no       | Shown after a successful signup when there is no redirect; the fields are disabled and the button hidden.                          |
| `[data-zanfia-error]`                     | no       | Shown when the request fails; the button is re-enabled.                                                                            |
| `data-zanfia-redirect="url"` (on the form) | no       | Sends the visitor to that URL after a successful signup instead of showing the success state. Absent = the form's own `redirectUrl` is NOT applied here; set the attribute when you want a redirect. |

The script posts to the origin it was loaded from (`https://zanfia.co`), never to your domain, so nothing has to be proxied. The endpoint answers the browser's cross-origin preflight and accepts any origin: the call is anonymous, carries no cookies, and the ids in the markup are public anyway. Abuse is limited per IP on the platform side.

### 3. What is sent

`POST https://zanfia.co/api/submitForm` with a JSON body:

```json
{
  "workspaceId": "work_…",
  "formId": "form_…",
  "email": "reader@example.com",
  "firstName": "Anna",
  "trackingConsent": false,
  "language": "pl"
}
```

`language` is the page's `<html lang>` (or the browser language) and picks the language of the confirmation e-mail. A `200` means the signup was recorded. For a double opt-in form the subscription, the tags and the consent apply only after the reader confirms from the e-mail; a single opt-in form subscribes immediately.

With custom fields the body also carries `"customFields": { "plan": "pro", "wedding_date": "2027-06-12" }` (see 6).

Other responses: `400` invalid payload (e-mail format, unknown form, `form/invalid-custom-fields` when a required custom field is empty or a value does not fit its type), `404` form not found, `429` too many requests from one IP, `5xx` platform error. The script treats anything but `2xx` as an error state.

### 4. After the signup

- **Thank-you page.** Put `data-zanfia-redirect` on the form to send the reader to your own page. The script also stores the address in `sessionStorage` so a second page carrying a `data-zanfia-phone-form` (the SMS reminder step) can attach a phone number to the same signup.
- **Pixels.** On a successful signup the script dispatches a `zanfia:form-submitted` event on `window` with `{ workspaceId, formId }`, so your own tracking can fire a lead.
- **Confirmation e-mail.** The sender name and the subject come from the form's confirmation e-mail settings (`forms update --confirmation-subject …` or the full copy through `confirmationEmailOverride`).

### 5. Webinar sessions

A form attached to a webinar with rolling sessions can offer a session picker. Add `data-zanfia-sessions="{workspaceId}/{roomId}"` to the form; the script loads the next sessions from the platform and inserts a select before the submit button.

### 6. Custom contact fields

A form saves the answers to your custom contact fields (Customers › Custom fields) only for the fields its settings list: open the form, the **Settings** tab, **Custom fields**, and add them there (or `set-signup-form-custom-fields` over MCP, `config.customFields` over the API, or ask the assistant). Each row there shows the input name and the e-mail token. An answer to a field the form does not list is dropped, even when the field exists.

In your markup each field is one element named `custom.<key>`; the value is checked against the field's type (a select takes the option key):

```html
<label>Plan<br /><select name="custom.plan" required><option value="pro">Pro</option></select></label>
<input type="hidden" name="custom.quiz_result" value="boho" />
```

A hidden input is how a quiz or a landing page passes a value the visitor does not type. The stored value prints in e-mails as `{{custom.<key>}}`. The hosted form (`/embed/form/…`) draws the listed fields by itself.

### 7. From your own server

When the sign-up happens in your own app (a calculator, a quiz, a checkout of another tool), your server can sign the person up through the same form with a workspace API key, in one call. There is no snippet and no per-IP limit; the key's own rate limit applies.

```bash
curl -X POST https://api.zanfia.com/forms/{formId}/submissions \
  -H "Authorization: Bearer $ZANFIA_API_KEY" -H "Content-Type: application/json" \
  -d '{ "email": "reader@example.com", "firstName": "Anna", "customFields": { "plan": "pro" },
        "marketingConsent": true, "consentStatement": true,
        "pageUrl": "https://example.com/calculator?utm_source=newsletter" }'
```

Or from the CLI: `zanfia forms submit <formId> --email reader@example.com --field plan=pro --marketing-consent --consent-statement --confirm`.

- **Marketing consent.** On a single opt-in form, the same rule as adding a client with the key. The person is subscribed when either:
  - the key has **With consent** (Integrations › API, MCP and CLI, column **Client consent**), or
  - your call sends `marketingConsent: true` with `consentStatement: true`, your statement that you hold this person's consent and answer for it.

  Otherwise they come in without consent. Send `marketingConsent: false` when the person said no: it wins over the key's setting. On a single opt-in form the form's automations still start: their marketing e-mails skip a person without consent, and transactional ones are sent. A key never gives SMS consent.
- **Double opt-in form.** A person who is not subscribed yet gets the form's confirmation e-mail, and only their click subscribes them and adds the form's tags. Until then the form's automations wait. With `marketingConsent: false` no e-mail goes out and no automation starts. A person who unsubscribed gets no e-mail either. A person who is already subscribed gets no e-mail: the form's tags land at once and its automations start, even with `marketingConsent: false`.
- **Contacts.** The fields are any active custom field of the workspace, and they **overwrite** the contact's values. A person who unsubscribed stays unsubscribed, and no automation starts for them. A new contact counts against your plan: when the plan is full the answer is `402` and nothing is saved.
- **Attribution.** The `utm_*` of `pageUrl` (or an `attribution` object) become the contact's first source. `refCode` links a new contact to your affiliate partner, but referral rewards are not counted. These sign-ups do not show in page statistics.
- **Pixels.** The server-side Meta Lead still goes out from `tracking`. Send `tracking.marketingConsent: false` when the person refused marketing cookies.

The answer says what happened: `marketingConsent` is `granted`, `already-subscribed`, `kept-unsubscribed`, `not-requested` or `confirmation-sent`. A repeated call is safe: it starts the automations once. The full list of fields and errors is in [Forms](https://zanfia.com/help/developer-api/forms).
