Skip to content
Corex

FormParts

Corex\Forms\Block\FormParts · class · Forms layer

The parts of one form, for a site that writes the form’s markup itself (spec 104, US3). A form’s markup() is handed this and returns HTML built from it. The stock form is built from the same parts, so a form drawn by hand validates, submits, shows its errors and is challenged as the stock one is, and keeps doing so when CoreX changes. A form cannot work without {@see self::attributes()} on its <form>, {@see self::hidden()} inside it, and {@see self::status()} inside it; nor, when it shows a challenge, without {@see self::challenge()}. Every field needs a wrapper carrying {@see self::fieldAttributes()} that holds its control and its {@see self::error()}. Every method returns markup or attributes that are already escaped.

__construct(string $slug, array $attributes, array $schema, string $hidden, string $submitLabel, FieldRenderer $fields, string $challenge)

Section titled “__construct(string $slug, array $attributes, array $schema, string $hidden, string $submitLabel, FieldRenderer $fields, string $challenge)”

Which of the parts this form cannot work without are absent from its own markup, named as the methods that supply them.

The attributes of the <form> element: the class the runtime binds, where and how it submits, its schema, its messages and its wording.

The fields nobody sees: the trap field, and the token field when the form is protected.

Where the provider’s challenge is shown, for a protected form on a site whose provider shows one (Turnstile, hCaptcha). Empty otherwise, so it is always safe to print. Put it before the submit button.

One field as the stock form draws it: wrapper, label, control, help text and error place.

What the element wrapping a field carries, so the runtime can find the field’s error place.

A field’s label, tied to its control.

control(string $name, array $extra): string

Section titled “control(string $name, array $extra): string”

The attributes of a control written by hand: its id and name, what describes it, and whether it is required. The site adds the element, its type and its classes.

Where a field’s error is written, and announced.

The submit button, with the form’s label.

Where the confirmation and the general error are announced.