mvccore / ext-form-field-text
MvcCore - 扩展 - 表单 - 字段 - 文本 - 表单字段类型 - 输入:text, 输入:email, 输入:password, 输入:search, 输入:tel, 输入:url 和 textarea。
v5.2.2
2024-02-19 15:44 UTC
Requires
- php: >=5.4.0
- mvccore/ext-form: ^5.2.17
- mvccore/mvccore: ^5.2.28
Suggests
- mvccore/ext-form-validator-special: MvcCore form extension with special text and numeric validators.
README
MvcCore 表单扩展,包含输入字段类型 text, email, password, search, tel, url 和 textarea 字段。
安装
composer require mvccore/ext-form-field-text
字段和默认验证器
input:text
,input:search
SafeString
- 默认配置
- XSS 字符串保护,默认配置,以安全的方式显示提交的值
MinMaxLength
- 默认未配置
- 通过 PHP
mb_strlen()
进行最小和最大验证
Pattern
- 默认未配置
- 通过 PHP
preg_match()
验证
input:password
(扩展自input:text
)密码
- 默认未配置
- 通过可配置的密码强度规则进行验证
SafeString
,MinMaxLength
,Pattern
- 默认未配置,...如上所述
input:email
(扩展自input:text
)电子邮件
- 默认配置
- 通过 PHP
filter_var($rawValue, FILTER_VALIDATE_EMAIL);
进行单/多电子邮件表单验证
SafeString
,MinMaxLength
,Pattern
- 默认未配置,...如上所述
input:tel
(扩展自input:text
)电话
- 默认配置
- 验证电话号码中不允许的字符,不验证国际电话号码格式
SafeString
,MinMaxLength
,Pattern
- 默认未配置,...如上所述
input:url
(扩展自input:text
)URL
- 默认配置
- 通过正则表达式进行 URL 验证,SSRF 保存值,可选 DNS 验证和其他许多选项
SafeString
,MinMaxLength
,Pattern
- 默认未配置,...如上所述
textarea
SafeString
- 默认配置MinMaxLength
,Pattern
- 默认未配置,...如上所述
特性
- 始终在服务器端检查属性
required
,disabled
和readonly
- 所有 HTML5 特定和全局属性(由Mozilla 开发者网络文档提供)
- 每个字段都有其内置的特定验证器,如上所述
- 每个内置验证器在必要时将表单错误添加到会话中,然后在错误页面上显示/渲染所有错误,并在用户提交后从会话中清除
- 任何字段都可以自然渲染或使用特定字段类/实例的自定义模板进行渲染
- 非常可扩展的字段类 - 每个字段都有公共模板方法
SetForm()
- 在字段实例被添加到表单实例后立即调用PreDispatch()
- 在任何字段实例渲染类型之前立即调用Render()
- 在表单实例渲染过程中对每个实例进行调用- 子方法:
RenderNaturally()
,RenderTemplate()
,RenderControl()
,RenderLabel()
...
- 子方法:
Submit()
- 在表单提交时对每个实例进行调用
示例
基本示例
$form = (new \MvcCore\Ext\Form($controller))->SetId('demo'); ... $username = new \MvcCore\Ext\Forms\Fields\Text(); $username ->SetName('username') ->SetPlaceHolder('User'); $password = new \MvcCore\Ext\Forms\Fields\Password([ 'name' => 'password', 'placeHolder' => 'Password', 'validators' => ['Password'], ]); ... $form->AddFields($username, $password);