Submit A Form

A release can declare forms. Visitors and other applications post answers to them, and publishers read the submissions. This needs forms turned on for your FOLD. A local FOLD has them on.

Declare A Form

Add forms/NAME.form.json to the directory. This one is forms/contact.form.json.

{ "fields": [{ "name": "email", "type": "email", "required": true }] }

A form has 1 to 50 fields with unique names. A name starts with a letter and continues with up to 63 letters, digits or underscores. A field is optional unless required is true.

Field type Accepted answer
text Text of up to 2,048 characters. Set minLength and maxLength to narrow it, or choices to allow 1 to 100 exact answers
email An email address of up to 320 characters
number A JSON number, or a numeric string in a URL-encoded post
boolean A JSON boolean, or true or false as text in a URL-encoded post

Post From Another Application

Read the form and save the X-Fold-Release header. It names the release your answers were collected against.

curl -fsi "$SITE/forms/contact"

Post the answers as JSON with that release and a new UUID as the key.

KEY=$(uuidgen)
curl -si "$SITE/forms/contact" \
  -H 'Content-Type: application/json' \
  -H "X-Fold-Release: $RELEASE" \
  -H "Idempotency-Key: $KEY" \
  --data '{"email":"reader@example.invalid"}'

A successful post returns HTTP 201 and a JSON receipt. If the response is lost, post again with the same key, release and answers to get the same receipt. HTTP 409 means the site has moved to a newer release, or the key was reused with different answers. Read the form again and confirm the answers before you start a new submission.

A client can also post URL-encoded fields, with the key in _key and the release in _release. Leave out optional fields that have no answer. FOLD rejects fields the form doesn't declare, and the body is limited to 16,384 bytes.

Post From A Page

An HTML page can hold a form that posts to a form declared in the same release. Write the action from the site root.

<form action="/forms/contact">
  <label for="email">Email</label>
  <input id="email" name="email" type="email" required />
  <button>Send</button>
</form>

Test In A Preview

Post to the form under a preview URL you've been granted. A valid post returns HTTP 200 with {"valid":true,"release":"…"} and stores nothing.

Read Submissions

A publisher pages through submissions, and reads a form's definition from a ready release.

pnpm fold submissions --limit 25
pnpm fold forms describe contact RELEASE_ID

Next: From source to private preview