Form schema
A form's fields are stored as a single JSON document. It is revisioned like page content, read and written through the /cms/api/form endpoint, and produced by the Forms ▸ Fields builder in the admin UI. How to read and write it over HTTP is covered in API reference §5; how the rendered form looks is covered in Styling forms.
The same document drives four consumers, which is why it is validated centrally and never interpreted loosely:
| Consumer | Uses it to |
|---|---|
| The builder UI | Render the field list and settings panels |
| The publisher | Generate the form's HTML into the static page |
| The submission endpoint | Validate what was posted, server side |
| Notifications and the submission viewer | Label and order the stored values |
Every submission records the schema version it was made against, and is always rendered and validated against that version — so rewording a question never retroactively changes what earlier answers meant.
1. Top level
{
"format": 1,
"fields": [ … ]
}
| Key | Required | Value |
|---|---|---|
format |
yes | Schema format version. Currently 1. This is not the form's revision id — that comes back as X-ID from a write. |
fields |
yes | Ordered array of elements. 1–100 entries, counting elements nested inside a fieldset. |
No other top-level keys are permitted.
2. Reserved fields
The publisher injects several fields into every generated form. Their keys all begin with _, and a schema may not define any key beginning with _ — that is what keeps author keys and reserved keys from ever colliding.
| Field | Purpose |
|---|---|
_form |
The form's id |
_version |
The schema version the page was published against |
_token |
Publish-time HMAC binding the submission to that form and version |
_page |
The path of the page the form was published into. Always present; authors do not configure it |
_robot, _human |
Present only when the form's anti-robot setting is on. These names are reserved; a schema can't use them. |
| (honeypot) | A decoy field whose name is derived per form. Any value in it scores as spam |
_pow |
Added by the published page's script: proof that the browser did a short piece of work before submitting, bound to _token. Present only where scripting ran; its absence is never held against a submission |
_elapsed |
Added by the same script: seconds between the form being opened and sent. A submission sent implausibly fast scores as spam |
These are stored with the submission and are visible in the submission viewer, but they are not part of the schema and are not author-editable.
3. Keys common to every element
| Key | Applies to | Default | Value |
|---|---|---|---|
key |
all | derived | ^[a-z][a-z0-9_]{0,39}$. Unique across the whole document, including nested elements. Derived from the element's label on first save and frozen from then on, so relabeling never orphans stored values. |
type |
all | — | One of the types in §4. |
label |
all inputs | — | 1–200 characters. Both the visible label and the source of key. (fieldset uses legend, paragraph uses text.) |
help |
all inputs | — | ≤300 characters, rendered beneath the field. |
required |
all inputs | false |
For checkbox, means the box must be checked. |
width |
all inputs | "full" |
"full" or "half". Two consecutive half fields share a row. |
visible_when |
all | — | See §6. |
Authors never type a key. It is shown only in an "Advanced" disclosure, for the benefit of API clients.
4. Element types
text
Single-line free text — names, company, subject lines.
| Key | Default | Value |
|---|---|---|
maxlen |
200 |
1–1000 |
minlen |
0 |
≤ maxlen |
format |
— | A named format from §7. Constrains the accepted characters. |
country |
— | Required when format is postal; see §7. |
placeholder |
— | ≤100 characters |
textarea
Multi-line free text — the message body.
| Key | Default | Value |
|---|---|---|
maxlen |
5000 |
1–65535. Always present — there are no unbounded text fields. |
minlen |
0 |
≤ maxlen |
rows |
6 |
2–30. Display height only. |
placeholder |
— | ≤100 characters |
Line count is not a validation rule — an unusually high line count contributes to the spam score instead, so no genuine submission is ever rejected for pressing Enter.
email
| Key | Default | Value |
|---|---|---|
placeholder |
— | ≤100 characters |
Length is fixed: local part ≤64 bytes, whole address ≤254 bytes. Validation is deliberately liberal — presence of @ with content on both sides, the length caps, and outright rejection of any CR/LF or control character (mail-header injection). There is no DNS or MX lookup. An address that fails a stricter syntax check is still accepted and stored, but contributes to the spam score, so an unusual-but-valid address is never silently lost.
The first email field in a form becomes the Reply-To of the notification message.
tel
| Key | Default | Value |
|---|---|---|
mindigits |
7 |
|
maxdigits |
15 |
The E.164 maximum |
placeholder |
— | ≤100 characters |
No country-specific rules. Everything except digits and a leading + is stripped for counting; both the raw string as typed and the digit-normalized form are stored.
url
No configurable keys. Maximum length is fixed at 250 characters, and only the http and https schemes are accepted — which also prevents a javascript: or data: URL reaching a notification email.
number
| Key | Default | Value |
|---|---|---|
min |
0 |
A negative minimum has to be set deliberately |
max |
— | Required |
step |
1 |
> 0 |
decimals |
0 |
0–4 |
display |
"input" |
"input" — spinbox · "scale" — radio row · "stars" |
labels |
— | {"min":"Poor","max":"Excellent"}. scale only. |
unit |
— | ≤20 characters, rendered after the input, e.g. "employees" |
aggregate |
derived | Whether values feed the metrics index. Defaults to true when display is not "input". |
One type covers both "how many employees" (display: "input") and a 1–5 satisfaction rating (display: "scale", min: 1, max: 5). The difference is rendering and whether an average means anything, not validation.
max is mandatory because maxlength has no effect on a numeric input — max is the only digit cap there is.
select
| Key | Default | Value |
|---|---|---|
options |
— | Required, see §5 |
placeholder |
— | Label for the empty leading option, e.g. "Choose…". Omitting it on a required select means the first real option is preselected. |
radio
| Key | Default | Value |
|---|---|---|
options |
— | Required, see §5 |
layout |
"vertical" |
"vertical" or "horizontal" |
checkbox-group
| Key | Default | Value |
|---|---|---|
options |
— | Required, see §5 |
minchecked |
0 |
|
maxchecked |
option count | ≥ minchecked |
layout |
"vertical" |
"vertical" or "horizontal" |
checkbox
A single checkbox whose label is the statement or question being answered — "I agree to the privacy policy", or "Do you use Linux?". A consent is the common use, and is normally required: true; a plain yes/no question is not.
Both answers are recorded, so "how many said yes" can be read against how many were asked.
The label text is copied into the submission record, so you can always show exactly what was agreed to or asked, even after the wording has since changed.
date
| Key | Default | Value |
|---|---|---|
min |
— | YYYY-MM-DD |
max |
— | YYYY-MM-DD, ≥ min |
no_past |
false |
Reject a date earlier than the day of submission |
no_future |
false |
Reject a date later than the day of submission |
Bounds are absolute dates only — there are no relative expressions, which avoids both wordiness and the ambiguity of adding months of differing length. no_past / no_future cover the common "not in the past" case without any arithmetic, and are evaluated in the site's timezone.
fieldset
{"type":"fieldset","key":"about_you","legend":"About you","fields":[ … ]}
| Key | Required | Value |
|---|---|---|
legend |
yes | 1–200 characters |
fields |
yes | Non-empty array. May not contain another fieldset — nesting is exactly one level deep. |
Renders as <fieldset><legend>, which gives correct grouping semantics for screen readers. A visible_when on a fieldset hides the entire group; the server then treats every child as absent — neither required, nor accepted if submitted.
Because a legend is a heading and the box is a divider, there are no separate heading or divider elements.
paragraph
| Key | Required | Value |
|---|---|---|
text |
yes | ≤1000 characters, plain text |
Explanatory prose between fields. No input, no stored value.
5. Options
Used by select, radio and checkbox-group. 1–50 entries.
"options": [
{"key":"sales","label":"Sales"},
{"key":"support","label":"Support"},
{"key":"other","label":"Something else"}
]
key is derived from label on first save and frozen thereafter, exactly as field keys are. Keys must be unique within the field, and labels must be non-empty and ≤200 characters. The author only ever types labels.
A submitted value that is not one of these keys is rejected. This is the reason option lists live in the schema rather than in page markup: the list that renders the <option> elements is the same list the server validates against, so the two can never drift.
6. Conditional visibility
"visible_when": {"field":"topic","op":"eq","value":"other"}
| Key | Value |
|---|---|
field |
Key of a choice element (select, radio, checkbox-group, checkbox) that appears earlier in the document, or its label if it is added in the same save (below) |
op |
eq · neq · in · checked · unchecked |
value |
A string for eq / neq; an array for in; omitted for checked / unchecked |
checked / unchecked apply to checkbox and checkbox-group; the comparison operators apply to select, radio and checkbox-group.
Referring to a field added in the same save. A field or option added in the document being saved has no key yet, so a condition may refer to it by its label, in field and in value. The server gives it its key and stores the condition with that key. Saved fields and options are referred to by key instead of label, and anything this form has ever used as a key is always read as a key: a condition that still refers to a removed field is refused, not attached to a new field whose label happens to match.
Conditions are evaluated twice:
- Client side, to show and hide fields as the form is filled in.
- Server side, as part of validation. A field whose condition is false is not required, and any value submitted for it is discarded.
An unanswered governing field reveals nothing: with no answer yet there is nothing to react to, so every operator — neq included — evaluates false until the field has a value. That matches what the page does before anything is clicked.
A visible_when on a fieldset hides its children too, whatever their own conditions say.
With JavaScript disabled every field renders visible, and the server-side evaluation still produces a correct result — so the form remains usable without scripting.
Because the referenced field must appear earlier and must be a choice element, forward references and dependency cycles cannot be expressed at all.
7. Text formats
The format key on a text element selects a named pattern. Authors choose from a list; they never write an expression. The server defines both the authoritative check and the pattern attribute emitted into the HTML, so client and server can never disagree.
format |
Accepts | Expression |
|---|---|---|
| (none) | Anything within the length limits | — |
letters |
Personal and place names: letters, marks, spaces, apostrophes, hyphens, periods | ^\p{L}[\p{L}\p{M}' \-\.]*$ |
alphanumeric |
ASCII letters and digits | ^[A-Za-z0-9]+$ |
digits |
Digits only, of any length within the limits | ^[0-9]+$ |
slug |
Lowercase words separated by single hyphens | ^[a-z0-9]+(?:-[a-z0-9]+)*$ |
postal |
A postal code; requires country |
see below |
postal requires a country:
country |
Expression (case-insensitive) |
|---|---|
us |
^[0-9]{5}(?:-[0-9]{4})?$ |
ca |
^[A-Za-z][0-9][A-Za-z] ?[0-9][A-Za-z][0-9]$ |
uk |
^[A-Za-z]{1,2}[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}$ |
The server evaluates these with PCRE in UTF-8 mode; the same source is emitted as the pattern attribute, which browsers compile as a Unicode-aware expression.
Adding a format to this table is a backwards-compatible change and does not increment format.
8. Limits
| Limit | Value |
|---|---|
| Whole document | 65,535 bytes |
| Elements | 100, counting those nested in a fieldset |
| Fieldset nesting | 1 level |
| Options per element | 50 |
| Label / legend | 200 characters |
| Help text | 300 characters |
| Paragraph text | 1,000 characters |
| Key | 40 characters |
| JSON nesting depth | 8 |
Sizes are measured in bytes, not characters, so a document of multi-byte labels cannot overflow the storage column.
9. Validation
One validator serves both the builder and /cms/api/form; there is never a second implementation. It reports errors in two tiers.
9.0 413 — too large
The document exceeds 65,535 bytes. Checked before parsing.
9.1 400 — not a schema document
Returned when the request body could not be understood as a schema at all. A plain-text message; no error list, because there is nothing to point at.
- Not valid JSON, or nested deeper than 8 levels.
- The top-level value is not a JSON object —
true,null,123,"text"and[]are all rejected here. formatis missing, is not an integer, or is a version this server does not support.fieldsis missing or is not an array.- An unknown top-level key is present.
9.2 422 — a schema document with problems
Returned when the document is structurally a schema but breaks one or more rules. The body is JSON, listing every failure:
{"errors":[
{"path":"fields[3].visible_when.field","message":"No field named \"topic\" appears earlier in the form"},
{"path":"fields[5].max","message":"Required"}
]}
path is a JSON path into the submitted document, so the builder can highlight the offending control and an API client can report precisely. All failures are returned at once, not just the first.
The rules:
fieldsis non-empty and contains at most 100 elements in total.- Every element is an object with a known
type. - Every key present is legal for that
type—maxlenon atext, not on anumber. keymatches^[a-z][a-z0-9_]{0,39}$, does not begin with_, and is unique across the whole document.label(orlegend, ortext) is present and within its length limit.minlen ≤ maxlen,min ≤ max,minchecked ≤ maxchecked ≤option count,step > 0,decimalsbetween 0 and 4,rowsbetween 2 and 30.- A
numberhas amax.labelsappears only whendisplayis"scale". - A choice element has 1–50 options, each with a non-empty label and a key unique within the element.
- A
textwithformat: "postal"has acountryfrom the supported list;countryappears only alongsideformat: "postal". - A
datehasmin ≤ maxwhere both are given. No rule may depend on the current date — a document that validates today must validate identically in ten years, so that stored versions can always be read back and re-saved. - A
fieldsethas a non-emptyfieldsarray containing no furtherfieldset. visible_when.fieldrefers to an existing choice element that appears earlier in the document;opis valid for that element's type;valueis present when the operator requires one and absent when it does not; every value underinmatches one of that element's option keys. A field or option added in the same save may be referred to by its label instead of its key.
Condition errors say what to change:
No field named "x" appears earlier in the form- No field has that key, or a field's condition refers to the field itself.
"x" is below this field. Move it above, or move this field below it.- The field exists, but appears after the one whose condition requires it.
"x" is inside this section. A section cannot depend on its own fields.- A section's condition refers to one of its own fields.
"x" is not a choice field. A condition can only depend on a choice field: select, radio, checkbox-group or checkbox.- The field it refers to is a text, number, date or other element without choices, or a section.
"Lastname" is a label. Name the field by its key, "lastname".- A saved field was named by its label instead of its key.
Not an option of "fruit": "Apple" is a label. Name the option by its key, "apple".- A saved option was named by its label instead of its key.
10. Example
{
"format": 1,
"fields": [
{"key":"your_name","type":"text","label":"Your name","required":true,
"maxlen":100,"format":"letters","width":"half"},
{"key":"your_email","type":"email","label":"Your email","required":true,"width":"half"},
{"key":"company","type":"text","label":"Company","maxlen":100},
{"key":"what_can_we_help_with","type":"select","label":"What can we help with?",
"required":true,"placeholder":"Choose…",
"options":[
{"key":"sales","label":"Sales"},
{"key":"support","label":"Support"},
{"key":"other","label":"Something else"}]},
{"key":"please_specify","type":"text","label":"Please specify","maxlen":100,
"visible_when":{"field":"what_can_we_help_with","op":"eq","value":"other"}},
{"key":"about_your_company","type":"fieldset","legend":"About your company",
"visible_when":{"field":"what_can_we_help_with","op":"eq","value":"sales"},
"fields":[
{"key":"number_of_employees","type":"number","label":"Number of employees",
"min":1,"max":100000,"step":1,"decimals":0,"display":"input","unit":"employees"},
{"key":"website","type":"url","label":"Website"},
{"key":"when_do_you_need_this_by","type":"date","label":"When do you need this by?",
"no_past":true}]},
{"key":"how_would_you_rate_our_response_time","type":"number",
"label":"How would you rate our response time?",
"min":1,"max":5,"step":1,"display":"scale",
"labels":{"min":"Poor","max":"Excellent"},"aggregate":true,
"visible_when":{"field":"what_can_we_help_with","op":"eq","value":"support"}},
{"key":"how_can_we_help","type":"paragraph",
"text":"Tell us as much as you can — the more detail, the faster we can respond."},
{"key":"message","type":"textarea","label":"Message","required":true,
"maxlen":5000,"rows":8},
{"key":"i_agree_to_the_privacy_policy","type":"checkbox",
"label":"I agree to the privacy policy","required":true}
]
}
11. Changing the format
format increments only for a change that would make an existing document invalid or alter its meaning. Adding an optional key, a new element type, or a new entry to the text-format or postal-country tables is backwards compatible and does not increment it.
Because every submission records the schema version it was made against, and /cms/api/form can read any historical version, older documents remain readable and renderable indefinitely.