evolutionphp/form_validation
Composer 安装命令:
composer require evolutionphp/form_validation
包简介
PHP Form Validation.
README 文档
README
Simple PHP Form Validator based in Code Igniter library.
Installation
Use Composer to install Logger into your project:
composer require evolutionphp/form_validation
Setting Validation Rules
Here is an example to set validation rules:
$form_validation = new \EvolutionPHP\FormValidation\FormValidation(); $form_validation->set_rules('username','Username','required');
A complete code looks like this:
<?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $form_validation = new \EvolutionPHP\FormValidation\FormValidation(); $form_validation->set_rules('username','Username','required'); if($form_validation->run() == false){ $error_msg = $form_validation->error_string(); } }
Setting Rules Using an Array
Before moving on it should be noted that the rule setting method can be passed an array if you prefer to set all your rules in one action. If you use this approach, you must name your array keys as indicated:
$rules = [ [ 'field' => 'username', 'label' => 'Username', 'rules' => 'required' ], [ 'field' => 'password', 'label' => 'Password', 'rules' => 'required|min_length[6]', 'errors' => [ 'required' => 'Password is required.' ] ] ] $form_validation->set_rules($rules);
Validating an Array (other than $_POST)
Sometimes you may want to validate an array that does not originate from $_POST data.
$data = [ 'username' => 'smith', 'password' => 'IAmGroot' ] $form_validation->set_data($data);
Important
For a full documentation visit the CodeIgniter Form Validation page.
Extra Validation Rules
| Rule | Parameter | Description | Example |
|---|---|---|---|
| valid_date | Yes | Fails if field does not contain a valid date. Any string that strtotime() accepts is valid if you don’t specify an optional parameter that matches a date format. So it is usually necessary to specify the parameter. | valid_date[d/m/Y] |
| valid_json | No | Fails if field does not contain a valid JSON string. | |
| uploaded | No | It works like 'required' but for $_FILES | |
| is_image | No | Fails if the file cannot be determined to be an image based on the mime type. | |
| mime_in | Yes | Fails if the file’s mime type is not one listed in the parameters. | mime_in[image/png,image/jpeg] |
| ext_in | Yes | Fails if the file’s extension is not one listed in the parameters. | ext_in[png,jpg,gif] |
| max_size | Yes | Fails if the uploaded file is larger than the second parameter in kilobytes (kb). | max_size[1024] |
| max_dims | Yes | Fails if the maximum width and height of an uploaded image exceed values. | max_dims[468,60] |
| min_dims | Yes | Fails if the minimum width and height of an uploaded image not meet values. | min_dims[468,60] |
| exact_dims | Yes | Fails if the width and height of an uploaded image has different values. | exact_dims[468,60] |
Use translated error messages
By default, error messages are located in /src/Lang/data.php, you can use your own translation loading a new array data:
$lang['form_validation_required'] = 'The {field} field is required.'; $lang['form_validation_is_image'] = 'The {field} field does not contains a valid image.'; $form_validation->set_language($data);
Authors
This library was primarily developed by CodeIgniter 3 and modified by Andres M.
evolutionphp/form_validation 适用场景与选型建议
evolutionphp/form_validation 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「validation」 「form validation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evolutionphp/form_validation 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evolutionphp/form_validation 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evolutionphp/form_validation 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
A Laravel Filament Forms slug field.
Adds request-parameter validation to the SLIM 3.x PHP framework
A jQuery augmented PHP library for creating and validating HTML forms
A Laravel validator for delimiter-separated list of emails.
A CakePHP behavior to validate foreign keys
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-07