monomelodies/formulaic
最新稳定版本:1.5.11
Composer 安装命令:
composer require monomelodies/formulaic
包简介
Object oriented PHP5 form tools
关键字:
README 文档
README
Object-oriented form utilities for PHP5.4+
This project is discontinued
Please see its successor: monolyth/formulaic
HTML forms suck. Well, no, they're superduper handy, but writing them and validating them server-side can be a pain. Formulaic offers a set of utilities to ease that pain.
Basic usage
Define a form with some fields and other requirements:
<?php use Formulaic\Get; use Formulaic\Search; use Formulaic\Button\Submit; class MyForm extends Get { public function __construct() { $this[] = (new Search('q'))->isRequired(); $this[] = new Submit('Go!', 'submit'); } }
In your template, either use the API to manually tweak your output, or simply
__toString the form to use the defaults:
<?php $form = new MyForm; echo $form;
You can __toString individual fields:
<?php $form = new MyForm; ?> <form name="search" method="get"> <!-- These two yield identical output using MyForm above: --> <?=$form[0]?> <?=$form['q']?> </form>
To validate your form:
<?php $form = new MyForm; if ($form->valid()) { // ...Perform the search... }
To get a list of errors:
<?php $form = new MyForm; if ($errors = $form->errors()) { // ...Do error handling, or give feedback... }
Forms can contain fieldsets:
<?php use Formulaic\Get; use Formulaic\Fieldset; use Formulaic\Search; use Formulaic\Button\Submit; class MyForm extends Get { public function __construct() { $this[] = new Fieldset('Global search', function($fieldset) { $fieldset[] = new Search('q'); }); $this[] = new Fieldset('Search by ID', function($fieldset) { $fieldset[] = new Search('id'); }); $this[] = new Submit('Go!'); } }
And in your output:
<form method="get"> <?=$form['Global search']?> <?=$form['Search by ID']?> <?=$form['submit']?> </form>
See the full documentation for all other options.
统计信息
- 总下载量: 175
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2015-01-20