astral-php / astral-form
Form helpers and partials for Astral MVC.
0.1.0
2026-03-29 08:02 UTC
Requires
- php: ^8.0
- astral-php/astral: ^1.1
Requires (Dev)
- phpunit/phpunit: ^9.6
This package is auto-updated.
Last update: 2026-05-03 15:01:42 UTC
README
Helpers et partials de formulaires pour Astral MVC.
astral-form fournit un FormBuilder léger, sans dependance front
supplementaire, pour generer des champs HTML coherents avec Tailwind
et afficher les erreurs issues de Core\Validator.
Compatibilite
- PHP:
^8.0 - Astral MVC:
^1.1
Installation
composer require astral-php/astral-form
Dans config/dependencies.php:
use Astral\Form\FormServiceProvider; return [ FrameworkServiceProvider::class, DatabaseServiceProvider::class, AppServiceProvider::class, FormServiceProvider::class, ];
Le provider enregistre:
Astral\Form\FormBuilderdans le container$formpartage global dans toutes les vues viaView::share()
Usage rapide
<?= $form->field( name: 'email', label: 'Adresse e-mail', value: $old['email'] ?? '', errors: $errors ?? [], options: ['type' => 'email', 'required' => true], ) ?>
Avec un select:
<?= $form->select( name: 'role', choices: ['user' => 'Utilisateur', 'admin' => 'Administrateur'], selected: $old['role'] ?? 'user', errors: $errors ?? [], ) ?> <?= $form->error('role', $errors ?? []) ?>
API du FormBuilder
field(string $name, string $label, mixed $value = null, array $errors = [], array $options = []): stringinput(string $type, string $name, mixed $value = null, array $errors = [], array $options = []): stringtextarea(string $name, mixed $value = null, array $errors = [], array $options = []): stringselect(string $name, array $choices, mixed $selected = null, array $errors = [], array $options = []): stringlabel(string $name, string $text, array $options = []): stringerror(string $name, array $errors, string $class = '...'): stringhasError(string $name, array $errors): boolfirstError(string $name, array $errors): ?stringattributes(array $attributes): string
Partials fournis
Les partials sont proposes dans views/astral-form/partials/:
field.phpinput-text.phpselect.phptextarea.php
Exemples
Des exemples complets sont disponibles dans examples/:
login.phpregister.phpprofile.php
Tests
Depuis la racine du projet Astral:
vendor/bin/phpunit
License
MIT