Forms
A form lives in any scene of any story, written with the same directives as the rest of Récit. It renders as a native HTML form that works without JavaScript, and as an accessible interactive form when JavaScript runs. Its answers go to your API, following the Form submission API: Récit hosts nothing.
Markdown
Try it
The form of examples/, rendered by this page from the same Markdown, its outer fence
one colon longer (see In a site). It plays in mock mode: pick the API's answer above
it, nothing is sent.
Request sent
Nothing sent yet.
The block
| Element | Role |
|---|---|
:::form{# | the form. id is required and unique in the project |
::field[Label]{name= | a field. name is required, structural, never translated; type defaults to text |
options= | the choices of select, radio, checkbox-; other= adds a free choice |
visible-if, required-if, enabled-if | conditions: name=value, name!=value, name (filled), !name (empty). Nothing else |
help="…" | a help text, linked to the field by aria- |
compute= | a computed number field, read-only (see « Computed fields » below) |
::consent[Text]{name version} | a consent box, never pre-checked; its version is sent with the answer |
::submit[Label] | the button; a translated default when absent |
:::fieldset[Legend] | a group of fields |
:::success, :::error | the text shown after the answer; the API's message replaces it |
Field types:
| Type | Sent as (JSON) | Notes |
|---|---|---|
text, tel, textarea | string | minlength, maxlength, pattern, rows (textarea) |
email, url | string | checked as an email address or URL |
number | number | min, max, step |
range | number | native slider (with a linked <output> when interactive); min and max are required, without step it advances by steps of 1 |
date | string | YYYY-MM-DD, min and max compared |
time | string | HH:MM (seconds optional), min and max in HH:MM |
datetime- | string | YYYY- (seconds optional), min and max in YYYY- |
select, radio | string | options= (other= adds a free choice on radio) |
checkbox | boolean | true when checked |
checkbox- | string[] | options= (other= adds a free choice) |
file | multipart file | accept and max-size (bytes); switches the form to multipart/ |
hidden | string | value= sent without a visible control |
The HTML attributes are kept as they are: required, min, max, minlength, maxlength,
pattern, step, autocomplete, placeholder, rows, accept, max-size (bytes) and value
(prefilled).
Attributes of the form: endpoint, contract (recit, the default, openapi, or formspree, see below), submit
(fetch, native or mock), encoding (form, the default, or json), method (POST, the
only one), antispam (honeypot, the default, turnstile with sitekey=, or none), auth
(none, publishable- with key=, or bearer, see below), privacy (a link to the privacy notice), retention (days the answers are kept),
upload (multipart, the default, or presigned, see Files sent first),
and openapi with operation (see below). The retention period (in days, 1 to 3650) is shown
to the visitor near the submit button; it must match the duration kept by the backend (the
resource's retentionDays): the block does not check it.
antispam= is opt-in: it loads Cloudflare Turnstile, a third-party script that receives
the visitor's address, only for that form, so the privacy notice must name it. sitekey= is the
widget's public key, never its secret; the token travels as _recit. (or
meta. in JSON), and the server checks it with siteverify before the answers
(createFormHandler takes turnstile:). It needs contract=.
forms in recit. and forms: in a story's front matter set defaults for every :::form
(endpoint, contract, submit, encoding, antispam, auth, publishableKey for key=,
turnstileSiteKey for sitekey=, privacy, retention and upload): the front matter overrides the config key by key, and an attribute
written on :::form wins over both.
Markdown
A :::fieldset[Legend] groups fields under a legend; it holds at least one ::field, never another
fieldset:
Markdown
Every attribute, one example each
Any attribute missing from these tables is an error, with its line.
:::form | Example |
|---|---|
id | :::form{# |
endpoint | :::form{# |
contract | :::form{# |
submit | :::form{# |
encoding | :::form{# |
method | :::form{# |
antispam | :::form{# |
auth | :::form{# |
key | :::form{# |
sitekey | :::form{# (the public site key of Cloudflare Turnstile, never its secret) |
privacy | :::form{# |
retention | :::form{# |
upload | :::form{# (each file is sent first, see below) |
openapi | :::form{# |
operation | :::form{# |
url | :::form{# (the page where the form is answered online; a printed form shows its QR code and address) |
::field | Example |
|---|---|
name | ::field[Your name]{name= |
type | ::field[Arrival]{name= |
required | ::field[Email]{name= |
min | ::field[Rating]{name= |
max | ::field[Slot]{name= |
minlength | ::field[Message]{name= |
maxlength | ::field[Your name]{name= |
pattern | ::field[Postcode]{name= |
step | ::field[Rating]{name= |
autocomplete | ::field[Your name]{name= |
placeholder | ::field[Website]{name= |
rows | ::field[Message]{name= |
accept | ::field[Resume]{name= |
max-size | ::field[Resume]{name= |
value | ::field[Source]{name= |
options | ::field[Size]{name= |
other | ::field[Diet]{name= |
help | ::field[Company]{name= |
visible-if | ::field[Company]{name= |
required-if | ::field[Company]{name= |
enabled-if | ::field[Company]{name= |
compute | ::field[Total]{name= |
hidden | ::field{name= (a field generated from OpenAPI only) |
Computed fields
A number field with compute= shows a value computed from other fields, as the reader types:
Markdown
The expression is closed: numbers, the names of number or range fields written before it
(another computed field included), + - * / and parentheses. Nothing else is evaluated. Write a
subtraction with spaces (a - b): a-b is one name. The field is read-only, takes no value= and is never required;
it stays empty while a field it reads is empty, or on a division by zero, and is rounded to the
decimals of its step. The value sent for it is never trusted: the reference server
(@recit/) recomputes it from the other answers, and checks its min and max like any
number. Without JavaScript, the field stays empty on the page and the server fills it in. On
paper, the field shows its formula with the labels it reads (« Computed: “Quantity” × “Unit price”
»), for the reader to work it out by hand.
A choice that needs one sentence of help under it is written as a :::field container, inside a
::::form (one more colon than the field): one list item per option, value=Label on its first
line and its description on the next lines. The label and the description may hold commas. A
container never takes options= as well, and a field generated from OpenAPI takes its options from
the operation's enum. A radio or a checkbox- shows the description under its choice, as
the choice's accessible description (aria-); a select keeps it in the definition
only, since an <option> holds no more than its label. The description is plain text: Markdown
emphasis or a link in it is read as its words.
Markdown
A pattern runs on the server for every value sent, so recit build, recit dev and recit form
refuse one whose matching can backtrack without bound: a repeated group whose iterations can overlap
((a+)+, ([a-z]+\s?)+, (a|ab)*, (a?a)+), a back-reference (\1), or three unbounded
repetitions in a row that can match the same characters (\d+\d+\d+, .*a.*b.*c). A repeated
group is accepted when it starts or ends with a separator none of its repetitions can match: write
[a- rather than ([a-z]+\s?)+, and [a- for a slug. The server
never runs a pattern on a value longer than its maxlength, or than 1,000 characters.
::consent | Example |
|---|---|
name | ::consent[I agree to be contacted]{name= |
required | ::consent[I agree to be contacted]{name= |
version | ::consent[I agree to be contacted]{name= |
::submit[Label] takes no attribute (::submit[Register]); :::success and :::error take none
either and hold the Markdown shown after the answer, as in the first example of this page.
A field outside the block
A ::field may be written elsewhere in the same scene, outside its :::form, with form= and the
form's id: beside a table, after a paragraph, before the form itself. It stays where it is written
and belongs to the form like any other field: the build checks it with the form's rules (its name
is unique among the form's fields, a condition may read it), and it enters the form's definition
and its published schema after the form's own fields, in the order of the scene. In the form's
definition (/forms/), such a field carries outside: among the form's fields,
never among the fields of a fieldset.
Markdown
On the page, each of its controls carries the HTML form attribute, so the browser sends and
checks it with the form, without JavaScript too. In a site, the form's component draws it in its
place once the page is loaded. A ::field outside a block without form=, or naming a form of
another scene, is an error with its line; inside a block, form= is an error, and a form whose
fields come from an OpenAPI operation takes no field from outside.
Fields from an OpenAPI operation
When an API already describes its requestBody in OpenAPI, the form can take its fields from it:
Markdown
openapi= (a YAML or JSON file, relative to the story) implies contract=; operation= is
the operationId, a POST without path parameter. The build reads the document (OpenAPI 3.0 or 3.1,
local $ref only) through a closed table:
| JSON Schema | Field |
|---|---|
string with format:, uri, date | email, url, date |
string with maxLength over 200 | textarea |
string with minLength, maxLength, pattern | text with the same HTML attributes |
enum (5 values or fewer, else select) | radio or select |
boolean | checkbox |
integer, number with minimum, maximum | number with min, max, step |
array of enum | checkbox- |
format:, contentMediaType | file (the operation must take multipart) |
title, description, default | label (else derived from the name), help, value |
x-, x-, x- | order, left out, autocomplete |
A nested object, oneOf/anyOf (other than with null), an array of objects or an external $ref
is an error with the line of the document, never a guess. readOnly properties are left out. The
servers[0].url and the path give the endpoint unless the block sets one.
A ::field{name= inside the block overrides a generated field: its label, help,
placeholder, autocomplete, value, rows and conditions; the overridden fields come first, in
their order. hidden leaves a field out, or sends it as a hidden value with value= (a required
property needs one). An unknown name is an error. recit form schema <id> -- prints
the JSON Schema of the data; -o, -- also writes the definition, /forms/.
recit build writes both files under forms/ in its output directory for each valid form it
renders.
Sending to Formspree
contract= sends the same block to a Formspree form, without its
SDK: Récit translates the body and the answers, nothing else.
Markdown
- The body is flat, urlencoded (multipart with a file, JSON with
encoding=): the fields of the author, nojson _recit.*entry and noIdempotency-, so a urlencoded request needs no preflight.Key - The honeypot travels as
_gotcha, the one Formspree reads; a ticked consent as its version (consent=), kept with the answers.2026- 10 - Formspree's errors land on their fields:
REQUIRED_reads asFIELD_ EMPTY required,TYPE_EMAILasformat,TYPE_NUMERICandTYPE_TEXTastype; an error of the whole form is shown above it.429waits forRetry-After, as with every contract. submit=andnative key=are refused at build: the translation needs JavaScript, and Formspree knows the form by its address.submit=mockplays Formspree's own answers.
Files sent first
By default a file field travels in the submission itself, as multipart/, and the API
receives the bytes. upload= sends each file first, straight to the storage the API
chooses (an object store), so the submission stays small and can use encoding=:
Markdown
- For each chosen file, the form asks
<endpoint>/for a ticket (JSON: the form, the field, the file's name, type and size). The API checksuploads accept=andmax-size=; a refusal lands on the field, like any error of the answers. - It sends the bytes where the ticket says:
PUTwith its headers (a presigned URL), orPOSTwith its fields then the file (a presigned policy). - It submits the answers with the ticket's reference as the field's value, instead of the file.
A file of a field hidden by visible-if is never sent. submit= is refused at build (the
two steps need JavaScript), and so are contract= and contract=, which take their
files in multipart. submit=mock accepts every ticket and sends nothing. On the API side, the
reference server takes uploads: (see the
contract).
Submission modes
fetch(default): the form checks the answers, posts them urlencoded (multipart with a file), maps the API's errors onto the fields, sends once on a double click and waits forRetry-After.native: a plain HTML<form action method=, without JavaScript."post"> mock: nothing leaves the page. A banner says so. For the dev server, demos and tests.
Rules the build checks
Each problem comes with its file and line:
- errors: a missing or duplicate form id, a duplicate
name, a condition on an unknown name, an option without a value, arangewithoutminandmax, a malformedminormaxonnumber,range,timeordatetime-,local mingreater thanmax(min>max) onnumber,range,date,timeordatetime-, an unknown type or attribute, alocal namestarting with_recit., a missingendpoint(unlesssubmit=mock), apatternthat can backtrack without bound, a:::fieldthat lists its options withoptions=as well, holds anything but one list, or lists an option without a value, and any value that looks like a secret; - warnings: a form that collects personal data (email, phone, a name) without
::consentnorprivacy=(an error inrecit build, which then neither renders the form nor writes its files underforms/; a warning withrecit build --and inno- strict recit dev), and an optional field withouthelp("is this field needed?").
On paper
A form printed in a PDF (a report or a book exported with recit export --) keeps its
labels, help texts, empty boxes and consent, and leaves out what only works on screen: the submit
button, the Back and Next buttons, the status line and the demo banner. With url=, the page where the form is answered
online, the printed form ends with a QR code of that page and its address, so a reader can answer
from a phone:
Markdown
On screen, the QR code and the address stay hidden. The QR code is drawn at build time, as a vector in the HTML: nothing is fetched and no script runs.
Paper shows every field, so a field with visible-if is printed with its condition in words, above
its label, in the story's language: visible- reads « Only if “Attendance” is “On
site” », the labels of the field and of its value as the reader sees them. On screen, the line
stays hidden and the script applies the condition.
A questionnaire on paper
recit convert survey. turns a questionnaire (format: form) into a report
that prints it whole. The steps of prose stay sections; the fields of every step go into one
:::form, a :::fieldset per step legended by its heading, the consent and the submit last, the
completion screen as the message after sending. The when of a step becomes the visible-if of
each of its fields, so paper writes « Only if “Which best describes you?” is “Developer” » above
them. Other prose of a step with fields has no place in a form: it is left out, with a warning.
recit export report. then prints it; -o report.json writes the report's twin. With
--url https://, the printed form ends with the QR code of the page where it is answered online.
A questionnaire on slides
A deck is shown, not filled in. recit convert survey. writes a
slide per step: its heading and prose kept, its questions in words where its fields were, each label
followed by its choices (« Which best describes you? (Developer, Designer, Other) »), and the
condition of a step written in words under its heading. The consent and the completion screen are
left out. A last slide, « Answer online » in the story's language, holds the QR code of --url and
its address. Without --url the deck ends on the last step, with a warning; an address that is not
http(s) is an error and nothing is written. -o deck.json writes the deck's twin.
--to webstory writes the same as web story cards, a card per step; the last card also carries a
call to action to --url, for the reader who holds the phone. A card that says too much is reported
when the story is built (webstory-, with its line).
On a web story card
A web story card cannot be filled in: a :::form on a card of a webstory shows the QR code of its
url= and the address, captioned « Answer online: » in the story's language, drawn like ::qr with
the project's utm:. Without url=, the form is an error with its line.
Markdown
At the end of a film
A film has no field either: a :::form in a scene of a format: story is its end screen, the
scene's heading above the QR code of url= and the address, captioned « Answer online: ». The CLI
draws it like a ::chart scene, as a still (recit dev, recit render). Without url=, the film
is an error with the form's line.
Markdown
Languages
Labels, help, options, the consent and the messages are translated in *.fr.md with the same id
and the same name. recit i18n check refuses a name, an option value or a consent version that
differs between languages. The messages of the form itself (required, errors, sending) come from the
en and fr packs of @recit/form.
Accessibility
Labels are always visible, required fields say so in words, help and errors are linked by
aria-, an invalid field has aria-invalid. After a failed attempt, a summary of the
errors with a link to each field takes the focus; the state of the submission is announced in a live
region.
A questionnaire in steps (preview)
A story with format: form is one questionnaire, one scene per step. The format is a preview: its
schema (form.json), JSON twin, build checks and React
player (@recit/) are in place. recit dev survey. plays it in the browser and
reloads it on each save; recit build writes a static page (index.html with the questionnaire and
its first step, and assets/ and form.css, which play the steps). examples/
holds this survey in English and French. In a site, the questionnaire has its own page, and
<StoryEmbed slug= plays it inside an MDX page.
Markdown
The form: section of the front matter (settings.form in the JSON twin) configures the
questionnaire:
| Key | Type / values | Role |
|---|---|---|
id | string | Required. Lowercase slug of the questionnaire (settings. in the JSON twin). |
endpoint, contract, … | same as forms: | Every default of :::form: the same keys as forms: (see The block). |
progress | steps | bar | none | Progress indicator across steps (steps by default; settings. in the JSON twin). |
review | boolean | Adds a recap step before sending (settings. in the JSON twin). |
Attributes on a step separator (--- id=…):
| Attribute | Example | Role |
|---|---|---|
when | --- id= | Step condition (scenes.when in the JSON twin), with the same closed operators as visible-if (name=value, name!=value, name, !name). |
end | --- id= | Bare word marking the completion screen (scenes.end in the JSON twin), one per story. |
Rules checked today, each reported with the line of the step's separator (an error unless noted):
- more than one
endstep; endwritten with a value (end=false);- a bare word other than
endon a separator (--- id=);thanks done - a step with no field nor text, in any of its languages;
- a
whenthat is not a valid condition; - a
whennaming an unknown field, or a field defined only in the same or a later step; - more than five fields (
::fieldand::consent) in a step (warning).
A form: section without id or with an unknown key is an error with its path
(/settings/).
The player
At build time, buildFormSteps of @recit/ compiles a format: form story into a
FormStepsDocument ({ document, problems }), assembling one form across every step while turning
each step's prose into HTML; recit dev and recit build call it for you. A
field inside a step with when inherits that condition and cannot set its own visible-if.
In the browser, <FormSteps document= of @recit/ (styled by
@recit/) plays the document—or its serialized JSON, validated by
FormStepsDocumentSchema (FormStepSchema validates a single step)—as a single accessible form:
TSX
- Steps and progress: shows one playable step at a time, moving focus to its heading on step
change, and announces progress in a polite live region (
stepstext by default, a<progress>bar withbar, or nothing withnone). - Navigation and keyboard: Next validates the current step's controls before advancing, pressing Enter in a field acts as Next, and Back (hidden on the first step) returns to the previous step without losing answers.
- Branches (
when): steps whosewhencondition does not hold are skipped, and their fields are neither required nor sent (@recit/also exportsform/ steps liveValuesto drop answers from steps whosewhenis false, alongsideplayableSteps,endStepandstepProgress). - Errors across steps: on a failed submission,
FormStepsopens the first step with an error, and each link in the error summary moves to the step holding that field and focuses its control (viaForm's optionalonErrorLinkprop,(name:: when it returnsstring) = > boolean true,Formleaves focus to the caller). - Review and end screen: with
review: true, a recap step before submission lists each shown answer alongside a Change button that jumps back to its step; after a successful submission, theendstep replaces the form (orForm's success message stays when there is noendstep). There is no draft saving and no timer.
In JSON
Form definition
The compiled definition written to /forms/ (FormBlockSchema of @recit/) is
validated by form-. Alongside the form
attributes (id, endpoint, contract, submit, encoding, antispam, auth, publishableKey
for key=, privacy, retention, upload, method, openapi, operation and url), it carries:
| Key | Type / values | Role |
|---|---|---|
fields | FormItem[] | Required. Ordered items of the form: each item is a field (fields.name required) or a fieldset (fields. + fields.). |
fields.type | string | One of the 16 field types above ("text" when absent). |
fields.label | string or Record<string, string> | Visible label of the field (omitted only on hidden). fields.help and fields. take the same localized shape. |
fields. | boolean | Marks the field required unconditionally. |
fields. | integer (>= 0) | Minimum character length; fields. (>= 1), fields.min, fields.max, fields., fields.step, fields.rows, fields. and fields.value mirror the HTML attributes. |
fields. | integer (>= 1) | Maximum character length. |
fields. | string | Accepted MIME types or extensions on type: "file". |
fields. | integer (> 0) | Largest file in bytes on type: "file" (max-size in Markdown). |
fields. | Array<{ value, label, description? | Choices of select, radio and checkbox-: structural options., localized options. and optional localized options. (the lines under an option of a :::field list, shown under the choice of a radio or checkbox-). |
fields.other | string or Record<string, string> | Adds a free-text choice with this label on radio or checkbox-. |
fields. | string | Condition (name=value, name!=value, name, !name) from visible-if; fields. and fields. match required-if and enabled-if. |
fields. | string | On type:: the closed expression of a computed field (compute= in Markdown), recomputed by the server. |
fields. | string or Record<string, string> | Required on a :::fieldset item: legend of the group. |
fields. | Field[] (non-empty) | Required on a :::fieldset item: nested fields (fields.), each taking the exact same FieldSchema keys as a top-level field, never another fieldset. |
consent | { name, label, required? | Optional ::consent box: structural consent.name, localized consent., optional consent. (boolean) and consent.. |
submitLabel | string or Record<string, string> | Optional button label from ::submit[Label] (a translated default when absent); success and error hold the localized :::success and :::error Markdown. |
The docs JSON twin
In a format: docs story's JSON twin (DocsSourceSchema, validated by
docs.json), the :::form directive stays in the scene's
Markdown body while front matter defaults and page navigation map to typed keys:
| Key | Type / values | Role |
|---|---|---|
settings. | object | Optional forms: defaults from the front matter (endpoint, contract, submit, encoding, antispam, auth, publishableKey, privacy, retention, upload). |
scenes.body | string or Record<string, string> | Optional Markdown or MDX content of the page, including :::form blocks (Scenes). |
scenes.notes | string or Record<string, string> | Optional author notes (:::notes). |
scenes. | boolean or { label? | Sidebar entry of the page (--- sidebar=), or an object with localized sidebar. (sidebar_) and numeric sidebar. (sidebar_); scenes.id, scenes.title and scenes.attrs follow Scenes. |
In a site
A site renders the block in its pages, .md and .mdx, with nothing to wire: @recit/site runs
the remark plugin of @recit/form on every page, in the site's language (metadata.lang), and
draws each form with the Form of @recit/form and its stylesheet. A broken form fails the build
with its file and line.
To draw the forms with a component of your own (a demo that never posts, for instance), map
RecitForm in the site's config:
TypeScript
A form with auth=bearer needs the token of the person signed in to the site. @recit/form never
reads a session: the site gives it, by mapping RecitForm to the Form with a token provider,
asked at each submission:
TSX
A session kept in an HttpOnly cookie has no token to give: the form then posts to an API of the
same site, which reads its cookie and checks the session in verifyBearer's place.
Only the React Form sends the token. A Form given no token sends no header, and the API answers
401 to every submission; the static HTML element of a form has no provider at all, so an
auth=bearer form needs the site's RecitForm mapped as above.
A site that still lists remarkForm in build. keeps working: the block is already
converted when its plugin runs.
In an MDX page, a container inside the form (:::fieldset, :::success, :::error) closes on
the first :::, the form's included: open the form with one colon more, ::::form{…}, and close it
with ::::, as the demo of this page does. A story compiled by recit build needs no extra colon:
it pairs the fences itself.
A story compiled by recit build renders the native form through the form directive handler of
@recit/.