Examples menu

๐Ÿ“ฌ Contact Form

Multipart file upload and server-side form validation. The form submits as multipart/form-data; text fields arrive in $c->input(), the file in $c->file(). Per-field error signals are pushed back via SSE.

No base64 overhead. Datastar's contentType: 'form' modifier submits the nearest <form enctype="multipart/form-data"> as a real multipart POST โ€” files travel as binary, not JSON blobs.
Two validation layers. HTML5 required / type="email" / minlength attributes make Datastar call reportValidity() before the request is even sent. The server then re-validates every field independently.
$c->file('attachment') returns the parsed upload array (name, type, tmp_name, size) if the upload succeeded, or null if no file was sent or the upload failed.
State shared via PHP references. The action and view closures share mutable variables with use (&$ref). No signals needed โ€” nothing is client-reactive. The SSE block re-render reads the updated values directly via Twig.
Success toggled server-side. On clean submission $submitted becomes true; the re-rendered block switches to the confirmation panel โ€” no page reload, no client branching.

๐ŸŽฏ Actions

submit

Validates all fields server-side. Mutates shared PHP reference variables on failure or on success, then calls $c->sync() to trigger a block re-render via SSE.

๐Ÿ‘ Views

contact-form.html.twig

Form with inline error signals and a success panel. Submitted as multipart/form-data via Datastar contentType: form.