seanmorris/form
Composer 安装命令:
composer require seanmorris/form
包简介
Simple, Object oriented forms for PHP.
README 文档
README
Rapid, themable forms for PHP.
The Form library allows you to rapidly develop, theme, and validate forms, so you can get back to programming.
Creating a Form
Creating a form is simple. Elements starting with a letter or number are fields. Elements starting with underscores are special keys. For example _method allows you to set the choose a GET or POST request for your form.
Elements starting with a letter or number are rendered directly into the <input> or <select> tag. Elements beginning with an underscore are passed to logic but not rendered.
For example, the _title attribute generates a <label tag for the form field.
$skeleton['_method'] = 'POST'; $skeleton['testField'] = [ 'type' => 'text' , '_title' => 'Test Field' ]; $skeleton['submit'] = [ '_title' => 'Submit' , 'type' => 'submit' ]; $form = new \SeanMorris\Form\Form($skeleton); echo $form->render();
Validation
Validators are specified on the _validators key. Its an array keyed by validator class. The values are arrays of arguments to pass to the constructor.
$skeleton['testField'] = [ 'type' => 'text' , '_title' => 'Test Field' , '_validators' => [ 'SeanMorris\Form\Validator\Regex' => [ '/.{8,}/' => '%s must be at least 8 characters' ] ] ];
Filtering and validating submitted values is simple:
$form->setValues($_POST); if($form->validate()) { // Values will only contain keys for each of the fields. $values = $form->getValues(); } else { $errors = $form->erorrs(); }
More...
For the field type list, validator list, and usage guide read DOCS.
For the guide to extending the library to create new field types, read EXTENDING.
统计信息
- 总下载量: 3.24k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2016-02-28