slick/form
Composer 安装命令:
composer require slick/form
包简介
HTML form manipulation library for slick
README 文档
README
Slick/Form is a package that helps you work with HTML forms. It allows form creation,
input validation and filtering and also helps rendering it as HTML in your views.
The goal is to create a Form object that can be worked in the different stages of an
HTTP request.
This package is compliant with PSR-2 code standards and PSR-4 autoload standards. It also applies the semantic version 2.0.0 specification.
Install
Via Composer
$ composer require slick/form
Usage
One of the greatest features of Slick/Form package is to facilitate the creation
and usage of HTML forms. You probably will need forms in your application and
you will need to create all the HTML for every input, validate that input in
submission process and filter the input before using it.
Slick/Form helps you with that. All you need is to define your form and its
validators and filters and you will have HTML rendering, input validation and
filter.
Form definition
Lets start with a very simple example: A login form (login-form.yml)
id: login-form elements: username: type: text label: Username validates: notEmpty: Username cannot be empty filters: - text password: type: password label: Password validates: notEmpty: Password cannot be empty remember: type: checkbox label: Remember me on this computer filters: - boolean buttonGroup: type: fieldset elements: submit: type: submit value: Sign in attributes: class: btn btn-primary
In your application controller
use Slick\Form\FormRegistry; class LoginController { public function login() { $form = FormRegistry::getForm('login-form.yml'); return compact('form'); } }
Form HTML rendering
And in your view:
<html> <head> <title>Login form</title> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> </head> <body> <div class="form-wrapper"> <?php print $form; ?> </div> </body>
the result should be as follows:
Form submission/validation
Now with our form in place we need to detect if the form was submitted and if its valid:
use Slick\Form\FormRegistry; class LoginController { public function login() { $form = FormRegistry::getForm('login-form.yml'); if ($form->wasSubmitted()) { if ($form->isValid()) { $data = $form->getValues(); // An associative array with submitted values // Do stuff with the values } else { // data is not valid } } return compact('form'); } }
The Form::wasSubmitted() and Form::isValid() methods encapsulate the retrieve
of submitted data and the validation process through all input validation chains.
The Form::getValues() will return an associative array with submitted values
filtered. For example the $data['remember'] is a Boolean value because it will
use the boolean filter as we set in the login-form.yml definitions file.
Testing
$ vendor/bin/phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email silvam.filipe@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
slick/form 适用场景与选型建议
slick/form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「form」 「slick」 「form manipulation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 slick/form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slick/form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 slick/form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
On-demand image manipulation service.
Laravel package for resized.co, the on-demand image manipulation service.
Manipulate images in pure PHP
Diese Contao 4 Erweiterung stellt Google reCAPTCHA V2 in Form eines neuen Formularfeldes im Formulargenerator bereit. This extension provides Google reCAPTCHA V2 in the form of a new form field in the form generator of Contao Open Source CMS.
universal slider extension for tinyslider, swiper, flexslider, ...
Slick/Http is an useful library for Web application foundation. It implements the PSR-7 message interface and has a middleware server, session handling and an HTTP client.
统计信息
- 总下载量: 2.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 11
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-24
