# Form

> Interactive form container that collects input values and submits to your page action handler.

`form()` (alias `form_action()`) wraps input components and submits their values to your `@aiui.page_action` handler—either on button submit or live with `submit_on_change=True`.

{
  "type": "form_action",
  "action": "save_agent",
  "submit_label": "Save Agent",
  "children": [
    {"type": "text_input", "label": "Agent Name", "value": "Researcher", "name": "name"},
    {"type": "select_input", "label": "Model", "options": ["gpt-4o", "gpt-4o-mini", "claude-3.7-sonnet"], "value": "gpt-4o", "name": "model"},
    {"type": "switch_input", "label": "Enable memory", "checked": true, "name": "memory"}
  ]
}

## Python

```python
import praisonaiui as aiui

aiui.form(
    "save_agent",
    children=[
        aiui.text_input("Agent Name", value="Researcher", name="name"),
        aiui.select_input("Model", options=["gpt-4o", "gpt-4o-mini"], value="gpt-4o", name="model"),
        aiui.switch_input("Enable memory", checked=True, name="memory"),
    ],
    submit_label="Save Agent",
)
```

## YAML

```yaml
- type: form_action
  action: "save_agent"
  submit_label: "Save Agent"
  children:
    - type: text_input
      label: "Agent Name"
      value: "Researcher"
      name: "name"
    - type: switch_input
      label: "Enable memory"
      checked: true
      name: "memory"
```

## Props

| Parameter | Type | Description |
|---|---|---|
| `action`, `children` | `str`, `list` | Server action name and list of input components. |
| `submit_label` | `str` | Submit button text (default `"Submit"`). |
| `actions` | `list[dict] \| None` | Optional named action buttons (`{"id", "label", "variant", "disabled", "submit"}`). Each button submits all collected form values plus `action: id`. |
| `baseline_key` | `str \| None` | Optional revision key; changing it resets the clean/dirty baseline reported to `<BlockTree onFormState={...} />`. |
| `method`, `update_url`, `submit_on_change` | options | Use `method="get"` to sync filters to URL query params, or `submit_on_change=True` for instant updates. |

## Named actions and draft state

Use `actions` for multi-button workflows (such as **Save draft**, **Preview**, and **Publish**), and pass `onFormState` on [`<BlockTree>`](https://ui.praison.ai/docs/features/plugins/browser-sdk.md) to track `{ action, values, dirty, busy, pendingAction }` without DOM event hacks:

```python
import praisonaiui as aiui

aiui.form(
    "draft_editor",
    baseline_key="rev-3",
    children=[
        aiui.textarea_input("Body", name="markdown", value="# Hello", rows=8),
    ],
    actions=[
        {"id": "save", "label": "Save draft", "variant": "default", "submit": True},
        {"id": "preview", "label": "Preview", "variant": "outline"},
        {"id": "publish", "label": "Publish", "variant": "secondary"},
    ],
)
```

Structured controls such as [`rich_text_input()`](https://ui.praison.ai/docs/components/rich-text-input.md), [`multiselect_input()`](https://ui.praison.ai/docs/components/multiselect-and-tags.md), and [`tags_input()`](https://ui.praison.ai/docs/components/multiselect-and-tags.md) participate in the exact same `onFormState`, `baseline_key`, and named-action contract and post their structured JSON values directly.

## Related pages

- [Button Group](https://ui.praison.ai/docs/components/button-group.md)
- [Inputs, Filters & Forms](https://ui.praison.ai/docs/components/inputs-and-forms.md)
- [Text & Textarea Input](https://ui.praison.ai/docs/components/text-input.md)
