dennis84 / formz
一个简单的PHP表单库,灵感来源于PlayFramework的表单组件
dev-master
2014-03-12 17:36 UTC
Requires
- php: >=5.4.0
- symfony/event-dispatcher: 2.*
Requires (Dev)
- doctrine/common: 2.*
- symfony/finder: 2.*
- symfony/http-foundation: 2.*
- symfony/validator: 2.*
- twig/twig: 1.*
This package is not auto-updated.
Last update: 2024-09-14 14:26:23 UTC
README
这是一个简单的PHP表单库,灵感来源于PlayFramework的表单组件。
示例
这是一个快速示例,让您了解formz能做什么。
<?php $builder = new \Formz\Builder(); $form = $builder->form([ // Creates a text field that must not be blank. $builder->field('name')->nonEmptyText(), // Creates a numeric field. $builder->field('age')->integer(), ], function ($name, $age) { // This is the apply function. Use this function to convert the submitted // data to your domain objects. return new User($name, $age); }, function (User $user) { // This is the unapply function. Use it to convert your domain models into // an associative array. This function is only needed if you want to fill a // form with existing values. return [ 'name' => $user->getName(), 'age' => $user->getAge(), ]; }); // Binds the $_POST data to the form. $form->bind($_POST); if ($form->isValid()) { // Get the applied data. In this example, this is the "User" object. $user = $form->getData(); }
更多示例
Formz拥有相当全面的测试覆盖率,展示了所有功能。