定制 modus/forms 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

modus/forms

最新稳定版本:2.1

Composer 安装命令:

composer require modus/forms

包简介

A form validation library for Modus Framework.

README 文档

README

Forms is a dead simple library for validating incoming data, whether that data be from the $_POST superglobal or from the CLI, or from any other source.

Setup

In order to use Forms, you need to extend the FormsBase class, and implement two values: $fields and configureValidations().

The $fields property contains an array of fields you'll be passing into the form, for the purposes of separating the valid content from content you don't care about. It should be an array of valid strings:

$fields = [
  'username',
  'password',
  'password_verify',
];

Once you have defined the $fields property, you can build your validations in the configureValidations() method.

protected function configureValidations()
{
  $filter = $this->filter;
  $filter->addSoftRule('username', $filter::IS, 'alnum');
  $filter->addSoftRule('username', $filter::IS_NOT, 'blank');
  $filter->addSoftRule('password', $filter::IS_NOT, 'blank');
  $filter->addSoftRule('password_verify', $filter::IS, 'equalToField', 'password');
}

Using Forms

Once you have completed basic setup, now you're ready to use Forms.

To populate the form, call the populateData method with an array of data to be populated and filtered.

To filter the data, call validate().

The getError, hasErrors and getErrors functions all provide access to various errors, if validate() should return false. You can use isValid() to determine if there are errors to be retrieved.

统计信息

  • 总下载量: 113
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-10