astral-php/astral-form 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

astral-php/astral-form

最新稳定版本:0.1.0

Composer 安装命令:

composer require astral-php/astral-form

包简介

Form helpers and partials for Astral MVC.

README 文档

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\FormBuilder dans le container
  • $form partage global dans toutes les vues via View::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 = []): string
  • input(string $type, string $name, mixed $value = null, array $errors = [], array $options = []): string
  • textarea(string $name, mixed $value = null, array $errors = [], array $options = []): string
  • select(string $name, array $choices, mixed $selected = null, array $errors = [], array $options = []): string
  • label(string $name, string $text, array $options = []): string
  • error(string $name, array $errors, string $class = '...'): string
  • hasError(string $name, array $errors): bool
  • firstError(string $name, array $errors): ?string
  • attributes(array $attributes): string

Partials fournis

Les partials sont proposes dans views/astral-form/partials/:

  • field.php
  • input-text.php
  • select.php
  • textarea.php

Exemples

Des exemples complets sont disponibles dans examples/:

  • login.php
  • register.php
  • profile.php

Tests

Depuis la racine du projet Astral:

vendor/bin/phpunit

License

MIT

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固