# forms
Wires `@payloadcms/plugin-form-builder` (forms + form-submissions collections) and
provides `submitForm` — a server function (called from a Server Action) that chains:
rate limit → Turnstile → validation against the form definition from the panel → storing the submission.
Emails are sent by the form-builder (Forms → Emails) through `mailAdapter()`.
## ⚠️ RULE: the form COMES FROM the builder in the panel (mandatory)
**Forms are built by the editor in the panel** (Forms collection), NOT by the developer in code.
This is a CMS — the client defines fields, labels, messages and the recipient. The front end
only RENDERS the form from the panel and submits it through `submitForm`.
**NEVER build your own hard-coded form** — with hand-written
fields, labels in JSX, your own validation. It breaks "nothing hard-coded" (the client cannot
change fields or texts) and skips the plugin's whole mechanism (Turnstile, rate limit,
GDPR consent, notifications).
| WRONG (your own form) | RIGHT (the plugin's builder) |
|---|---|
| `` in JSX | fields from the Forms collection (panel) |
| labels/messages in code | labels per language in the panel |
| your own validation/submit | `submitForm` (Turnstile+consent+mail) |
| the client cannot change the form | the client edits fields in the panel |
**How to do it right:** the editor creates a form in the Forms collection → a block renders it
with `` → it is submitted through `sendForm` (`createSubmitAction` → `submitForm`). Fields,
labels, messages, recipient — all from the panel.
If a form needs a field the builder does not have — add it through the `fields`
configuration (see below) or extend the plugin. Do NOT hard-code your own form.
## Dependency
```json
"dependencies": { "@payloadcms/plugin-form-builder": "3.90.2" } // same version as payload
```
(the plugin's peer dependency: `^3.90.2`)
## Config (payload.config.ts)
```ts
ipalKit({
forms: {
redirectRelationships: ['pages'], // a form can redirect to a Page
// fields: { date: false, … }, // default: text, textarea, email, number, date,
// // time, select, radio, checkbox, checkboxGroup, message, step
},
})
```
`forms` options (`FormsOption`):
| Option | Default | Description |
|---|---|---|
| `adminGroup` | `'Forms'` | group in the panel; `false` = Payload's default; `admin.group` in overrides wins |
| `fields` | see below | builder field types; `false` turns a type off, an object (block) replaces it; `true` = the default ipal block |
| `redirectRelationships` | — | collections a form can redirect to |
| `formOverrides` / `formSubmissionOverrides` | — | collection overrides (`fields` as a function + any collection settings) |
| `emailLayout` | `false` | nice emails + the Site settings → E-mails tab |
| `beforeEmail` | — | the form-builder's `beforeEmail` (after the layout, when `emailLayout`) |
| `consentFieldName` | `'consent'` | name of the GDPR consent field for `submitForm` / `createSubmitAction` (the call's argument wins) |
`payment` is always off — `fields: { payment: true }` does **not** turn it on (the value `true`
is skipped); it can only be turned on by passing a block object. `country` / `state` keep the form-builder's
default settings.
Adds the **Forms** (the editor builds forms) and **Form Submissions**
(submissions) collections — in the panel in the **Forms** group with the labels "Form/Forms" and
"Submission/Submissions" (no overrides needed in the project). A different group:
`forms: { adminGroup: 'Content' }`; Payload's default: `adminGroup: false`. Emails after a submission are sent by the form-builder according to the form's **Emails**
tab — through the adapter from `email:` in the config (the "Emails" section below).
## Front end — RenderForm (recommended, one line)
The whole front end of a panel form lives in the plugin. The project has the block and the classes:
```tsx
// src/blocks/FormBlock/Component.tsx
import { RenderForm } from '@intecion/ipal-kit/rsc'
```
- `form` — the relation from the block (depth ≥ 1; an ID or null → nothing renders),
- `action` — `sendForm` from `createSubmitAction` (below), `texts` — `getFormTexts(locale)` from `lib/content`
(Form messages → Form messages),
- `classNames` — the **only** place for looks (`src/components/forms/formClasses.ts`, template in ipal-form);
the plugin has no styles at all. Keys: `form, progress, step, stepTitle, stepDescription, fields,
field, fieldHalf, fieldFull, label, input, textarea, select, checkbox, checkboxLabel, choices,
legend, choice, choiceInput, choiceLabel, message, error, formError, turnstile, actions, back,
next, submit, success, required, fixed`. For CSS there are also `data-ipal="form"`, `data-type`, `data-width`, `data-step`.
- options: `requiredMark` (e.g. `" *"`), `converters` / `richTextClassName` (rich text looks),
`linkOptions` (`await getLinkOptions(locale)` — redirect to a page from the panel), `turnstileTheme`
(default `'page'`), `values` (below).
`RenderForm` (server) renders **message** blocks and the confirmation through `RenderRichText`, binds
the action to the form and the language, resolves the redirect and gives the browser **only the public part of the
form** — the Local API reads with `overrideAccess`, so the document has the Emails tab (company addresses);
a hand-written `` used to send them in the HTML. Underneath it is `BuilderForm` (client).
### Field types in the panel
text, email, textarea, number, **date**, **time** (1.11.1), select, **radio**, checkbox, **Checkbox group**,
message, **Step** (+ country/state as text). Turning a type off: `forms.fields: { date: false }`.
**Placeholder** (1.11.1): text, email, textarea and number have a localized "Placeholder" field — a hint
in the empty field ("e.g. 10:00–12:00"). `BuilderForm` and `useBuilderForm` (`getInputProps`, `getTextareaProps`)
pass it on by themselves. Your own block with this field: `withPlaceholder(block)` / `placeholderField` from the root;
the time block: `timeBlock`. New fields in form blocks = a migration (`pnpm payload migrate:create`).
| Type | Value | The server checks |
|---|---|---|
| radio, select | one value | only values from the panel |
| Checkbox group | `string[]` (stored as "www, seo") | only values from the panel, no duplicates, `minSelected`/`maxSelected` |
| date | `YYYY-MM-DD` | a real date |
| time | `HH:MM` (``) | a time 00:00–23:59 |
| Step | — (split) | not a field |
### Multi-step form
A **Step** block (title, description, per language) starts a new screen; fields above the first Step are screen 1.
`BuilderForm`: "Step 1 of 3" (`stepOf`), Next validates only the current step, Back keeps the
values, focus moves to the new step, Turnstile is on the last step, a field error from the server goes back
to the step with that field. Button texts: Form messages → `next`, `back`, `stepOf`.
### Conditional fields and steps ("Show only when")
Every form block (built-in, **Checkbox group**, **Step**, message) has a
**Show only when** group in the panel (`showWhen`): `field` — the technical name of another field, `values` — option values,
comma-separated (empty = when that field is filled in / checked). An empty `field` = always visible.
- On a field: the field shows up only for a matching answer (e.g. "What sets the deadline?"
only when `deadline = fixed`).
- On a **Step**: the whole step (with its fields) drops out when the condition does not match — the following steps are renumbered
("Step 2 of 3"). This is how a brief is built: screen 1 picks areas (Checkbox group), each following
Step has `showWhen: { field: 'areas', values: 'web' }`.
- A field in a hidden step is hidden, even when its own condition matches; a condition that points at a hidden field
does not match either. The name of a field that does not exist (a typo) or a cycle hides the field — you can see it in the preview.
- One shared rule `visibleFields(fields, values)` (`@intecion/ipal-kit`, `/client`) — the browser
(`useBuilderForm`/`BuilderForm`: what to show, validate and send) and the server (`validateSubmission`):
a hidden field **is not required and is not stored**, even when someone sends it by hand.
Exception: the GDPR consent field (`consent`) is always enforced — a condition cannot turn it off.
- The `FieldCondition` type (`{ field, values }`) for your own markup on `useBuilderForm`; `splitSteps(fields, isShown)`
skips hidden fields and steps, keeping the original `index` (message blocks render by it).
- The new group = columns `show_when_field` / `show_when_values` in the form block tables →
after updating, generate a migration (`payload migrate:create`).
### Field values from the page (`values`, 1.11.0)
The page knows a field value the visitor does not type — the chosen product variant, category, offer.
The editor adds a plain text field to the form (e.g. `subject`, "Regarding"), and the page fills it:
```tsx
// a value known on the server (the "coming soon" category)
```
A field with `values` is shown read-only (`