# Fields, Logic & Formulas

Both the REST API (`create_form` / `update_form`) and MCP tools accept a strongly validated `fields` array plus `settings.logicRules`.

## Supported Field Types

### Input Fields (20 types)

| `type` | Description & Key Properties |
| --- | --- |
| `text` | Single-line text; optional `format`: `"iban"`, `"vat_eu"`, `"postal_nl"`, `"postal_eu"`, `"phone_eu"`, `"kvk_nl"` |
| `email` | Validated email address (first email field populates `submitterEmail`) |
| `textarea` | Multi-line text (`rows`, `minLength`, `maxLength`) |
| `number` | Numeric value (`min`, `max`, `step`) |
| `tel` | Telephone number |
| `url` | HTTP/HTTPS URL |
| `date` | ISO `YYYY-MM-DD` date (`min`, `max` support `"today"`) |
| `time` | `HH:MM` time |
| `select` | Dropdown menu (`options: [{ value, label, calcValue? }]`) |
| `radio` | Single-choice radio buttons (`options`) |
| `checkboxes` | Multi-select checkboxes (`options`, `minSelected`, `maxSelected`) |
| `checkbox` | Boolean checkbox (`checkboxLabel`) |
| `consent` | Mandatory GDPR consent checkbox (`privacyUrl`, `privacyLabel`) |
| `file` | Two-step private EU file upload (`accept[]`, `maxSize`, `max`) |
| `hidden` | Hidden value populated from URL query param (`fromQuery`) |
| `signature` | HTML5 canvas signature pad uploaded as PNG to private EU storage (`height`, `penColor`) |
| `rating` | Star rating (`style: "stars"`, 1-5) or NPS scale (`style: "scale"`, 0-10) |
| `matrix` | Grid of `rows[]` x `columns[]` (`cellType: "radio" | "checkbox" | "text"`) |
| `address` | Structured EU address (`street`, `houseNumber`, `postalCode`, `city`, `country`) |
| `repeater` | Dynamic repeatable list of `subFields[]` (`minRows`, `maxRows`, `addLabel`) |
| `image_choice` | Visual choice cards with `imageUrl`, `columns`, `multiple` |
| `calculation` | Safe read-only math field (`formula`, `prefix`, `suffix`, `decimals`, `hidden`) |
| `product_list` | EU order catalog / donation / fixed amount with `vatRatePercent`, `pricesIncludeVat`, `coupons[]`, `stockLimit` |
| `appointment` | Live time-slot booking (`durationMinutes`, `bufferMinutes`, `maxBookingsPerSlot`, `timezone`, `availableDays`, `startTime`, `endTime`) |

### Layout Blocks (5 types)

`heading` (`level: 2|3|4`), `paragraph` (`content`), `divider` (`style: "solid"|"dashed"|"dotted"`), `image` (`src`, `alt`, `caption`), and `section` (starts a new multi-step page with `nextLabel` / `prevLabel`).

## Conditional Visibility (`showIf`)

Every field may define a single `ShowIfRule` or compound `ShowIfGroup` (`match: "all" | "any"`). Referenced fields **must appear earlier** in the `fields` array so visibility is strictly acyclic:

```json
{
  "id": "fld_vat",
  "type": "text",
  "name": "vat_number",
  "label": "EU VAT number",
  "format": "vat_eu",
  "showIf": {
    "match": "all",
    "rules": [
      { "field": "customer_type", "operator": "eq", "value": "business" },
      { "field": "country", "operator": "neq", "value": "non_eu" }
    ]
  }
}
```

Supported operators: `eq`, `neq`, `in`, `not_in`, `contains`, `filled`, `empty`, `gt`, `gte`, `lt`, `lte`.

## Form-Level Logic Rules (`settings.logicRules`)

| Action `type` | Behavior |
| --- | --- |
| `skip_step` | Skip a `section` step (`targetStep`) when condition matches |
| `set_value` | Assign a literal or calculated value to `targetField` |
| `set_required` | Dynamically toggle `required: true | false` on `targetField` |
| `set_disabled` | Dynamically disable `targetField` |
| `thank_you` | Override confirmation `message` or safe `redirectUrl` on submit |

## Safe Calculations & Answer Piping

- Calculations use a sandboxed recursive-descent parser (zero `eval`): `{seats} * 49 + count(attendees) * 15`.
- Functions supported: `round()`, `ceil()`, `floor()`, `abs()`, `min()`, `max()`, `count(field)`.
- **Answer Piping:** Use `{{field_name}}` inside labels, paragraphs, success messages, auto-responder emails, PDF filenames, and BlokForms Sign agreement bodies.
