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.
Public API
Section titled “Public API”__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)”missingFrom(string $markup): array
Section titled “missingFrom(string $markup): array”Which of the parts this form cannot work without are absent from its own markup, named as the methods that supply them.
attributes(array $extra): string
Section titled “attributes(array $extra): string”The attributes of the <form> element: the class the runtime binds, where and how it submits, its schema, its messages and its wording.
hidden(): string
Section titled “hidden(): string”The fields nobody sees: the trap field, and the token field when the form is protected.
challenge(): string
Section titled “challenge(): string”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.
field(string $name): string
Section titled “field(string $name): string”One field as the stock form draws it: wrapper, label, control, help text and error place.
fieldAttributes(string $name): string
Section titled “fieldAttributes(string $name): string”What the element wrapping a field carries, so the runtime can find the field’s error place.
label(string $name): string
Section titled “label(string $name): string”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.
error(string $name): string
Section titled “error(string $name): string”Where a field’s error is written, and announced.
submit(array $extra): string
Section titled “submit(array $extra): string”The submit button, with the form’s label.
status(): string
Section titled “status(): string”Where the confirmation and the general error are announced.