mvccore / ext-form-field-text
MvcCore - Extension - Form - Field - Text - form field types - input:text, input:email, input:password, input:search, input:tel, input:url and 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 form extension with input field types text, email, password, search, tel, url and textarea field.
Installation
composer require mvccore/ext-form-field-text
Fields And Default Validators
input:text
,input:search
SafeString
- configured by default
- XSS string protection to safely display submitted value in response, configured by default
MinMaxLength
- not configured by default
- validation by PHP
mb_strlen()
for min. and max.
Pattern
- not configured by default
- validation by PHP
preg_match()
input:password
(extended frominput:text
)Password
- not configured by default
- validation by configurable password strength rules
SafeString
,MinMaxLength
,Pattern
- not configured by default, ...description above
input:email
(extended frominput:text
)Email
- configured by default
- single/multiple email form validation by PHP
filter_var($rawValue, FILTER_VALIDATE_EMAIL);
SafeString
,MinMaxLength
,Pattern
- not configured by default, ...description above
input:tel
(extended frominput:text
)Tel
- configured by default
- validation for not allowed chars in phone number, no validation for international phone number form
SafeString
,MinMaxLength
,Pattern
- not configured by default, ...description above
input:url
(extended frominput:text
)Url
- configured by default
- url validation by regular expression, SSRF save value, optional DNS validation and many other options
SafeString
,MinMaxLength
,Pattern
- not configured by default, ...description above
textarea
SafeString
- configured by defaultMinMaxLength
,Pattern
- not configured by default, ...description above
Features
- always server side checked attributes
required
,disabled
andreadonly
- all HTML5 specific and global atributes (by Mozilla Development Network Docs)
- every field has it's build-in specific validator described above
- every build-in validator adds form error (when necessary) into session and than all errors are displayed/rendered and cleared from session on error page, where user is redirected after submit
- any field is possible to render naturally or with custom template for specific field class/instance
- very extensible field classes - every field has public template methods:
SetForm()
- called immediatelly after field instance is added into form instancePreDispatch()
- called immediatelly before any field instance rendering typeRender()
- called on every instance in form instance rendering process- submethods:
RenderNaturally()
,RenderTemplate()
,RenderControl()
,RenderLabel()
...
- submethods:
Submit()
- called on every instance when form is submitted
Examples
- Example - CD Collection (mvccore/example-cdcol)
- Application - Questionnaires (mvccore/app-questionnaires)
Basic Example
$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);