Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

FormBinder
in package
implements ComponentBinder

The binder for pages without JavaScript, and the protocol's reference client. Components render as ordinary forms: submitting runs the action and the endpoint answers with a 303 back to the page. Set the component's $tag = 'form' so its controls and action buttons sit inside a form.

Other binders build on this one: HtmxBinder adds hx-* attributes to the same markup, so the no-JS path keeps working under htmx too.

Protocol headers it understands from scripted clients: Zeal-Request: 1 (async), Zeal-Trigger: <field>. It answers with Zeal-Events (JSON), Zeal-Redirect, and Zeal-Reload: 1.

Table of Contents

Interfaces

ComponentBinder
Decides which HTML attributes make a component interactive in the browser, and how endpoint side effects (events, redirects, reloads) are signalled.

Methods

actionAttributes()  : array<string, string|bool|null>
Attributes for an element that triggers an action.
isAsync()  : bool
Whether the request came from this binder's client script (rather than a plain form post that expects a redirect back to the page).
modelAttributes()  : array<string, string|bool|null>
Attributes for a form control bound to a #[Model] property.
refusalHeaders()  : array<string, string>
Extra headers for a refused request (400/403/404), e.g. telling the client not to swap the error text into the page.
response()  : array{status: int, headers: array}
Status and headers for an endpoint outcome.
rootAttributes()  : array<string, string|bool|null>
Extra attributes for the component's outer element.
triggerField()  : string|null
The name of the form control that triggered the request, if the client reports it.

Methods

actionAttributes()

Attributes for an element that triggers an action.

public actionAttributes(Component $component, string $url, string $argsJson) : array<string, string|bool|null>
Parameters
$component : Component
$url : string
$argsJson : string

the action arguments, JSON-encoded

Return values
array<string, string|bool|null>

isAsync()

Whether the request came from this binder's client script (rather than a plain form post that expects a redirect back to the page).

public isAsync(array<string|int, mixed> $server) : bool
Parameters
$server : array<string|int, mixed>

CGI-style request variables (HTTP_*)

Return values
bool

modelAttributes()

Attributes for a form control bound to a #[Model] property.

public modelAttributes(Component $component, string $prop, Model $model, string $updateUrl, bool $preserve) : array<string, string|bool|null>
Parameters
$component : Component
$prop : string
$model : Model
$updateUrl : string

the component's _update endpoint

$preserve : bool

true when this control triggered the current update and should be left untouched by the swap

Return values
array<string, string|bool|null>

refusalHeaders()

Extra headers for a refused request (400/403/404), e.g. telling the client not to swap the error text into the page.

public refusalHeaders() : array<string, string>
Return values
array<string, string>

response()

Status and headers for an endpoint outcome.

public response(Outcome $outcome, array<string|int, mixed> $events, string|null $redirect) : array{status: int, headers: array}
Parameters
$outcome : Outcome
$events : array<string|int, mixed>

event name → detail

$redirect : string|null
Return values
array{status: int, headers: array}

rootAttributes()

Extra attributes for the component's outer element.

public rootAttributes(Component $component, string|null $submitUrl) : array<string, string|bool|null>
Parameters
$component : Component
$submitUrl : string|null

the URL of the component's $submit action, if any

Return values
array<string, string|bool|null>

triggerField()

The name of the form control that triggered the request, if the client reports it.

public triggerField(array<string|int, mixed> $server) : string|null
Parameters
$server : array<string|int, mixed>
Return values
string|null
On this page