Status

Reference for the Status module: post-redirect-get status messages and form validation. A handler validates posted data against per-field rules, redirects with a success or error message and an optional data payload, and a following page reads and renders the outcome. Messages carry a session-bound hash so they cannot be forged.

This page is a pure reference. For how the framework fits together, see the Guide.

Classes
  • Status - validate posted data and redirect with a signed success or error message.
  • StatusUi - render the current status message, once per page.

Status

Static functions for the post-redirect-get pattern. Validate runs a map of field validators over posted data and, on any error, redirects to an error url with the per-field messages; on success the handler calls Success. Each redirect carries a status_hash tying the message to the session, checked by ValidateHash before anything is trusted. The Validate* factory functions each return a validator callable.

Error

Status::Error(string $url, string $message, array $data = null): void

Redirect to a url with an error message and optional data payload, then exit. Appends a session-bound hash so the message cannot be forged.

NameTypeDescription
$urlstringThe url to redirect to.
$messagestringThe error message to carry.
$dataarrayAn optional data payload, encoded into the url as JSON.

Returns void Sends a redirect header and exits.

GetParameters

Status::GetParameters()

Parse the current request query string into a name to value map, url-decoding each part.

Returns A map of query parameter name to value.

GetValidationError

Status::GetValidationError(string $name)

The per-field error message for a field, when the current request is a validated error redirect; null otherwise.

NameTypeDescription
$namestringThe field name to read the error for.

Returns The error message, or null.

GetValidationPreviousValue

Status::GetValidationPreviousValue(string $name)

The previously submitted value for a field, taken from the status data payload when the hash is valid; null otherwise.

NameTypeDescription
$namestringThe field name to read the previous value for.

Returns The previous value, or null.

Hash

Status::Hash(string $message, string $type, string $data): string

Compute the SHA-256 hash binding a message, type and data payload to the current session and the site secret.

NameTypeDescription
$messagestringThe status message.
$typestringThe status type, such as success or error.
$datastringThe encoded data payload, or an empty string.

Returns string The hex-encoded hash.

Success

Status::Success(string|null $optionalUrl, string $message, array $data = null): void

Redirect with a success message and optional data payload, then exit. Uses the current route when no url is given, and appends a session-bound hash.

NameTypeDescription
$optionalUrlstring|nullThe url to redirect to, or null for the current route.
$messagestringThe success message to carry.
$dataarrayAn optional data payload, encoded into the url as JSON.

Returns void Sends a redirect header and exits.

Validate

Status::Validate(array $postData, string|null $optionalErrorUrl, array $validation)

Run each field validator over the posted data. On any error, redirect to the error url with the per-field messages; otherwise return the validated values in order.

NameTypeDescription
$postDataarrayThe posted field values, keyed by field name.
$optionalErrorUrlstring|nullThe url to redirect to on error, or null for the current route.
$validationarrayA map of field name to a validator callable.

Returns The list of validated values, in field order.

ValidateBoolean

Status::ValidateBoolean()

Build a validator that accepts 0 or 1 and returns the value as a boolean.

Returns A validator callable.

ValidateEmail

Status::ValidateEmail()

Build a validator that checks the value is a valid email address.

Returns A validator callable.

ValidateFile

Status::ValidateFile(array $allowedMimeTypes = [])

Build a validator that checks a file was uploaded without error, and optionally that its MIME type is allowed.

NameTypeDescription
$allowedMimeTypesarrayAllowed MIME types, or empty to allow any.

Returns A validator callable.

ValidateFileRead

Status::ValidateFileRead(array $allowedMimeTypes = [])

Build a validator that checks an upload, reads its contents and returns an object with the contents, MIME type and file extension.

NameTypeDescription
$allowedMimeTypesarrayAllowed MIME types, or empty to allow any.

Returns A validator callable.

ValidateFloat

Status::ValidateFloat(float $min = null, int $max = null)

Build a validator that parses the value as a float and checks it against optional bounds.

NameTypeDescription
$minfloatThe minimum allowed value, or null for no minimum.
$maxintThe maximum allowed value, or null for no maximum.

Returns A validator callable.

ValidateHash

Status::ValidateHash(): bool

Check that the status hash in the current request matches the message, type and data, tying it to this session.

Returns bool True when the hash is valid.

ValidateInteger

Status::ValidateInteger(int $min = null, int $max = null)

Build a validator that parses the value as an integer and checks it against optional bounds.

NameTypeDescription
$minintThe minimum allowed value, or null for no minimum.
$maxintThe maximum allowed value, or null for no maximum.

Returns A validator callable.

ValidateObject

Status::ValidateObject(string $objectName)

Build a validator that parses the value with the named class's FromJson function, returning the resulting object.

NameTypeDescription
$objectNamestringThe class whose FromJson function parses the value.

Returns A validator callable.

ValidatePassword

Status::ValidatePassword(int $minLength = 0, int $maxLength = null)

Build a validator that checks the length of a password and marks the value private, so it is not echoed back on error.

NameTypeDescription
$minLengthintThe minimum allowed length.
$maxLengthintThe maximum allowed length, or null for no maximum.

Returns A validator callable.

ValidatePhoneNumber

Status::ValidatePhoneNumber()

Build a validator that checks the value is a valid phone number.

Returns A validator callable.

ValidateString

Status::ValidateString(int $minLength = 0, int $maxLength = null)

Build a validator that checks the length of a string against optional bounds.

NameTypeDescription
$minLengthintThe minimum allowed length.
$maxLengthintThe maximum allowed length, or null for no maximum.

Returns A validator callable.

ValidateWithFiles

Status::ValidateWithFiles(array $postData, array $filesData, string $errorUrl, array $validation)

Like Validate, but reads each field from the uploaded files when present, otherwise from the posted data.

NameTypeDescription
$postDataarrayThe posted field values, keyed by field name.
$filesDataarrayThe uploaded files, keyed by field name.
$errorUrlstringThe url to redirect to on error.
$validationarrayA map of field name to a validator callable.

Returns The list of validated values, in field order.

StatusUi

Renders the current status message. Reads the request parameters, verifies the hash, and emits a status element styled by type, or a generic message when the hash does not validate. Renders at most once per page.

Properties

PropertyTypeDescription
StatusUi::$alreadyAddedboolWhether the message has already been rendered this page; starts false.
Functions

Message

StatusUi::Message()

Render the current status message once, choosing success, error or info styling by type, or a generic message when the hash is invalid.

Returns Nothing; writes the status markup to the output.