Download the PHP package alaa/magento2-input-validation without Composer
On this page you can find all versions of the php package alaa/magento2-input-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alaa/magento2-input-validation
More information about alaa/magento2-input-validation
Files in alaa/magento2-input-validation
Package magento2-input-validation
Short Description Magento2 Rv Input Validation Based on Respect Validation
License MIT
Informations about the package magento2-input-validation
Magento Input Validation
Based on Respect Validation
Check full list of Rules
Installation
- Install by composer
composer require alaa/magento2-input-validation
- Enable the module
php bin/magento module:enable Alaa_RvInputValidation
- Magento upgrade
php bin/magento setup:upgrade
Usage
1. Backend
This is very simple to use in the backend, you can use the method of your choice that suits the requirement
- validteInput: this will validate input with a single rule. it accepts two arguments input value as a string and a rule as an array.
- validate: this will validate input with multiple rules. it loops through rules and call
validateInput
method. - validatePostData and validateGetData: this will validate multiple inputs and multiple rules for each input
The array rule elements are:
- class: required class name such as Email, NotEmpty, Between and etc. This is used to instantiate the validation rule object
- args: an optional element used to pass into the validation class constructor
Example
2. Frontend
This is very simple to use in the frontend for custom forms. Like shown in the example below, it is straight forward to learn how to apply validation. The rules here, can be either a sinle rule and a single json object or an array of rules. In the first inline method uses an array of validation rules and the second method in the init script uses a single json object to apply rules.
The validation happens on each input after clicking outside the input area, if the validation is successful it will show a basic green message. If the validation fails, then it will show a basic red message and add a new class to mark as invalid input value. Once the user fills the form, then upon submitting the form will validate and continue if validation is successful and stops if not.
The rule has rule name which is the validation class, args which are optional and name which is optional to use in the message.
The validation results can be overriten by overriding the Alaa/RvInputValidation/view/frontend/web/js/rv-input-results.js
Example
Contribution
Feel free to raise issues and contribute
Licence
MIT