Download the PHP package samsonphp/validation without Composer
On this page you can find all versions of the php package samsonphp/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samsonphp/validation
More information about samsonphp/validation
Files in samsonphp/validation
Package validation
Short Description SamsonPHP validation module
License Open Software License (OSL) v 3.0
Homepage http://samsonos.com/
Informations about the package validation
SamsonPHP validation module
SamsonPHP validation implementation
Documentation
Follow official documentation.
Installation
You can install this package through Composer:
The packages adheres to the SemVer specification, and there will be full backward compatibility between minor versions.
Testing
Usage example
Using FieldValidator
Just create instance of FieldValidator class and pass options to it:
And if you want get result of validation you have to call this method:
In this example:
- el - [required] Selector to field, can be string or s() element
- insertTo - Selector to field which can dysplay error message, can be string or s() element
- styleList - Prefix whcih will instet to message text(default: '')
But there can be a lot of options:
- trim - Need remove prefix and suffix spaces
- fieldErrorClass - Class which will be added to field, can be string or array.(default: ['class-error-field-', 'class-error-field'])
If there is array then first element of it will be prefix to all false passed validators.
For example
Will add such classes to field: <input ... class="class-error-field-required class-error-field-regexp class-error-field">
- showErrorBlock - Show error block or not. Default if insetTo element passed then block will show. If you want hide error block then pass false to it
-
insertToType - Where insert error block(default:__MODE_INSERT_TO_PARENT__):
__MODE_INSERT_TO_DEFAULT__ - There no changes with insertTo element
__MODE_INSERT_TO_PARENT__ - Find elemnet insert to in parent element of this field
-
showErrorBlockType - Where output classes(default:MODE_SHOW_ERROR_BLOCK_DEFAULT):
MODE_SHOW_ERROR_BLOCK_DEFAULT - Change classes in field
MODE_SHOW_ERROR_BLOCK_PARENT - Change classes in parent block
Crate custom validator
There very easy to create new validator. It can be class validator or alias
For create new validator just create class with export and validate methods export method will return object which will be added to main field object validate method which validate field with custom login
Constructor of class can receive field object
There is simple required validator:
You need add your validator to register validator array
required method will be added to field instance and can be access as
and such validator can be added
And you can use alias validator
There is when you need override some default values form another class validator and save it as new validator.
For example lets create url validator which use regExp validator
As you can see there is only one methond in object which return new object which will be used for extending
And you have to add to register array this validator as object without creating
And you can use it as:
But You should not use this validator with regExp
Contributing
Feel free to fork and create pull requests at any time.
Security
If you discover any security related issues, please use this repository issue tracker.
License
Open Software License ("OSL") v 3.0. Please see License File for more information.