Configuration reference
このコンテンツはまだ日本語訳がありません。
Overview
Section titled “Overview”This guide describes form model conventions and runtime behavior for metadata and validation errors.
Form model declaration
Section titled “Form model declaration”Create form models by extending BaseFormModel and declaring typed public properties that represent fields.
<?php
declare(strict_types=1);
namespace App\FormModel;
use UIAwesome\FormModel\Attribute\{FieldConfig, Hint, Label, Placeholder};use UIAwesome\FormModel\BaseFormModel;
final class SignInForm extends BaseFormModel{ #[Hint('Use your account email address.')] #[Label('Email address')] #[Placeholder('name@example.com')] #[FieldConfig(['class' => ['w-full rounded-md border border-slate-300 px-3 py-2']])] public string $email = '';
public string $password = '';
public function getHints(): array { return [ 'password' => 'Use at least 8 characters.', ]; }
public function getLabels(): array { return [ 'password' => 'Password', ]; }
public function getPlaceholders(): array { return [ 'password' => 'Enter your password', ]; }
public function getRules(): array { return [ 'email' => ['required', 'email'], 'password' => ['required', 'string'], ]; }
public function getFieldConfigs(): array { return [ 'password' => [ 'class' => ['w-full rounded-md border border-slate-300 px-3 py-2'], ], ]; }}Property metadata attributes
Section titled “Property metadata attributes”You can declare metadata directly on properties with attributes:
#[Hint('...')]#[Label('...')]#[Placeholder('...')]#[FieldConfig([...])]
When a property has both attribute metadata and map metadata, the attribute value is used first.
Metadata access behavior
Section titled “Metadata access behavior”getHint(),getLabel(), andgetPlaceholder()resolve values from attributes first, then map methods.- Missing labels fall back to generated title-case labels.
getRule()returns field rules ornullwhen no rules exist.getFieldConfig()resolves field configuration from attributes first, then map methods.
$label = $form->getLabel('email');$placeholder = $form->getPlaceholder('email');$rules = $form->getRule('email');$fieldConfig = $form->getFieldConfig('email');Nested metadata
Section titled “Nested metadata”- Use dot notation to access metadata from nested form models.
- Nested paths work for hints, labels, placeholders, rules, and field configuration.
$hint = $form->getHint('profile.address.city');$label = $form->getLabel('profile.address.city');$rules = $form->getRule('profile.address.city');Error lifecycle
Section titled “Error lifecycle”addError()appends a message to one field.setErrors()replaces all field error collections.clearError()clears all errors or one field.getFirstErrors()returns the first error per field.getErrorSummary()flattens all messages for rendering.hasError()andisValidated()report current error state.
$form->addError('email', 'Email is required.');
$errors = $form->getErrors();// ['email' => ['Email is required.']]
$firstErrors = $form->getFirstErrors();// ['email' => 'Email is required.']
$summary = $form->getErrorSummary();// ['Email is required.']