FormModelInterface
API reference › Form Model › FormModelInterface
Implemented by 1 type
Defines the contract for form models with validation metadata and field errors.
Usage example:
final class UserForm extends BaseFormModel{ public string $email = '';}
$form = new UserForm();$form->addError('email', 'Email is invalid.');Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
add() abstract | Adds a new property to the model. | UIAwesome\ |
addError() abstract | Adds an error for a field. | FormModelInterface |
clearError() abstract | Clears errors for one field or all fields. | FormModelInterface |
getData() abstract | Returns the raw data for the model. | UIAwesome\ |
getError() abstract | Returns errors for one field. | FormModelInterface |
getErrors() abstract | Returns validation errors indexed by field name. | FormModelInterface |
getErrorSummary() abstract | Returns a flattened error summary. | FormModelInterface |
getFieldConfig() abstract | Returns the field configuration for one field. | FormModelInterface |
getFieldConfigs() abstract | Returns field configuration arrays indexed by field name. | FormModelInterface |
getFirstError() abstract | Returns the first error for one field. | FormModelInterface |
getFirstErrors() abstract | Returns the first validation error indexed by field name. | FormModelInterface |
getHint() abstract | Returns the hint text for one field. | FormModelInterface |
getHints() abstract | Returns hint text indexed by field name. | FormModelInterface |
getLabel() abstract | Returns the label text for one field. | FormModelInterface |
getLabels() abstract | Returns label text indexed by field name. | FormModelInterface |
getModelName() abstract | Returns the model name that this model class should use. | UIAwesome\ |
getNames() abstract | Returns the list of property names. | UIAwesome\ |
getPlaceholder() abstract | Returns the placeholder text for one field. | FormModelInterface |
getPlaceholders() abstract | Returns placeholder text indexed by field name. | FormModelInterface |
getRule() abstract | Returns validation rules for one field. | FormModelInterface |
getRules() abstract | Returns validation rules indexed by field name. | FormModelInterface |
getTypes() abstract | Returns the list of property types indexed by property names. | UIAwesome\ |
getValue() abstract | Returns the value (raw data) for the specified property. | UIAwesome\ |
has() abstract | Checks if the model has the specified property. | UIAwesome\ |
hasError() abstract | Checks whether errors exist. | FormModelInterface |
isEmpty() abstract | Whether the model has no loaded raw data. | UIAwesome\ |
isType() abstract | Checks if the property is of the specified type. | UIAwesome\ |
isValidated() abstract | Checks whether a field has been validated successfully. | FormModelInterface |
load() abstract | Populates the model with input data. | UIAwesome\ |
setErrors() abstract | Replaces all field errors. | FormModelInterface |
setValue() abstract | Sets the value for the specified property. | UIAwesome\ |
setValues() abstract | Sets values for multiple properties. | UIAwesome\ |
toArray() abstract | Returns model properties as an array. | UIAwesome\ |
Method details
Section titled “Method details”addError()
Section titled “addError() ”abstract public function addError(string $field, string $error): voidAdds an error for a field.
Usage example:
$form->addError('email', 'Email is invalid.');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
$error | string | Error message to append. |
clearError()
Section titled “clearError() ”abstract public function clearError(string|null $field = null): voidClears errors for one field or all fields.
Usage example:
$form->clearError('email');$form->clearError();Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string| | Field name, or null to clear all fields. |
getError()
Section titled “getError() ”abstract public function getError(string $field): array<int, string>Returns errors for one field.
Usage example:
$errors = $form->getError('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
array<int, string>: Error list for the field.
getErrors()
Section titled “getErrors() ”abstract public function getErrors(): array<string, array<int, string>>Returns validation errors indexed by field name.
Usage example:
$allErrors = $form->getErrors();Returns
array<string, array<int, string>>: Errors indexed by field name. Returns an empty array when no errors exist.
getErrorSummary()
Section titled “getErrorSummary() ”abstract public function getErrorSummary(list<string> $onlyFields = [], bool $first = false): array<int|string, string>Returns a flattened error summary.
Usage example:
$summary = $form->getErrorSummary(['email', 'username']);Parameters
| Parameter | Type | Description |
|---|---|---|
$onlyFields | list<string> | Fields to include. Uses all fields when the list is empty. |
$first | bool | Whether to return only the first error of each field. |
Returns
array<int|string, string>: Flat list of error messages when $first is false; field-indexed first errors when $first is true.
getFieldConfig()
Section titled “getFieldConfig() ”abstract public function getFieldConfig(string $field): array<string, mixed>Returns the field configuration for one field.
A field configuration maps a method name to the argument, or list of arguments, applied to the field or to the widget that renders it.
Usage example:
$emailFieldConfig = $form->getFieldConfig('email');// ['class' => ['w-full rounded-md']]Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
array<string, mixed>: Field configuration for the field. Returns an empty array when the field has no configuration.
getFieldConfigs()
Section titled “getFieldConfigs() ”abstract public function getFieldConfigs(): array<string, array<string, mixed>>Returns field configuration arrays indexed by field name.
Each configuration maps a method name to the argument, or list of arguments, applied to the field or to the widget that renders it.
Usage example:
$fieldConfig = $form->getFieldConfigs();// ['email' => ['class' => ['w-full rounded-md']]]Returns
array<string, array<string, mixed>>: Field configuration arrays indexed by field name.
getFirstError()
Section titled “getFirstError() ”abstract public function getFirstError(string $field): stringReturns the first error for one field.
Usage example:
$firstError = $form->getFirstError('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
string: First error for the field, or an empty string when no errors exist.
getFirstErrors()
Section titled “getFirstErrors() ”abstract public function getFirstErrors(): array<string, string>Returns the first validation error indexed by field name.
Usage example:
$firstErrors = $form->getFirstErrors();Returns
array<string, string>: First errors indexed by field name. Returns an empty array when no errors exist.
getHint()
Section titled “getHint() ”abstract public function getHint(string $field): stringReturns the hint text for one field.
Usage example:
$hint = $form->getHint('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
string: Hint text for the field.
getHints()
Section titled “getHints() ”abstract public function getHints(): array<string, string>Returns hint text indexed by field name.
Usage example:
$hints = $form->getHints();Returns
array<string, string>: Hint text indexed by field name.
getLabel()
Section titled “getLabel() ”abstract public function getLabel(string $field): stringReturns the label text for one field.
Usage example:
$label = $form->getLabel('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
string: Label text for the field.
getLabels()
Section titled “getLabels() ”abstract public function getLabels(): array<string, string>Returns label text indexed by field name.
Usage example:
$labels = $form->getLabels();Returns
array<string, string>: Label text indexed by field name.
getPlaceholder()
Section titled “getPlaceholder() ”abstract public function getPlaceholder(string $field): stringReturns the placeholder text for one field.
Usage example:
$placeholder = $form->getPlaceholder('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
string: Placeholder text for the field.
getPlaceholders()
Section titled “getPlaceholders() ”abstract public function getPlaceholders(): array<string, string>Returns placeholder text indexed by field name.
Usage example:
$placeholders = $form->getPlaceholders();Returns
array<string, string>: Placeholder text indexed by field name.
getRule()
Section titled “getRule() ”abstract public function getRule(string $field): array<mixed, mixed>|nullReturns validation rules for one field.
Usage example:
$emailRules = $form->getRule('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
array<mixed, mixed>|null: Validation rules for the field, or null when no rules are defined.
getRules()
Section titled “getRules() ”abstract public function getRules(): iterable<string, array<mixed, mixed>>Returns validation rules indexed by field name.
Usage example:
$rules = $form->getRules();Returns
iterable<string, array<mixed, mixed>>: Validation rules indexed by field name.
hasError()
Section titled “hasError() ”abstract public function hasError(string|null $field = null): boolChecks whether errors exist.
Usage example:
$hasAnyError = $form->hasError();$hasEmailError = $form->hasError('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string| | Field name, or null to check all fields. |
Returns
bool: true if errors exist, otherwise false.
isValidated()
Section titled “isValidated() ”abstract public function isValidated(string $field): boolChecks whether a field has been validated successfully.
Usage example:
$isValid = $form->isValidated('email');Parameters
| Parameter | Type | Description |
|---|---|---|
$field | string | Field name. |
Returns
bool: true if the field exists in the error map with no messages, otherwise false.
setErrors()
Section titled “setErrors() ”abstract public function setErrors(array<string, array<int, string>> $values): voidReplaces all field errors.
Usage example:
$form->setErrors(['email' => ['Email is invalid.']]);Parameters
| Parameter | Type | Description |
|---|---|---|
$values | array<string, | Error messages indexed by field name. |