display_errors()
public function display_errors(array $data = []): ?string
Description
Displays validation errors in one of three formats: general HTML list, inline field‑specific errors, or JSON API response. This method is the object‑oriented counterpart to the validation_errors() helper function.
The format is determined by the first_arg value in the $data array:
- null or omitted – General errors for all fields (wrapped in
<ul class="validation-errors">) - string (field name) – Inline errors for a specific field
- integer (400‑499) – JSON response with HTTP error code
Parameters
| Parameter | Type | Description |
|---|---|---|
| $data | array | Associative array with optional keys:
|
Return Value
| Type | Description |
|---|---|
| string|null |
|
Example Usage
Notes
- Errors are retrieved from
$_SESSION['form_submission_errors']. - In JSON mode (HTTP code), the script terminates after output – no return value.
- For inline errors, an empty string is returned if the field has no errors.
- After errors are displayed, they are cleared from session (to prevent duplicate display).
- Use the helper
validation_errors()for simpler, function‑based access.