rlanvin / php-form
Lightweight form validation library for PHP
Installs: 61 188
Dependents: 0
Suggesters: 0
Security: 0
Stars: 34
Watchers: 5
Forks: 7
Open Issues: 0
Requires
- php: >=5.4.0
- ext-mbstring: *
Suggests
- ext-intl: Intl extension is useful for validating formatted numbers
README
Lightweight form validation library for PHP, with a concise syntax and powerful use of closures. It can validate traditional form submissions as well as API requests.
Basic example
// create the form with rules $form = new Form\Validator([ 'name' => ['required', 'trim', 'max_length' => 255], 'email' => ['required', 'email'] ]); if ( $form->validate($_POST) ) { // $_POST data is valid $form->getValues(); // returns an array of sanitized values } else { // $_POST data is not valid $form->getErrors(); // contains the errors $form->getValues(); // can be used to repopulate the form }
Complete doc is available in the wiki.
Requirements
- PHP >= 5.4
mbstring
extensionintl
extension recommended to validate numbers in local format
If you are stuck with PHP 5.3, you may still use version 1.1.
Installation
The recommended way is to install the lib through Composer.
Just add this to your composer.json
file:
{ "require": { "rlanvin/php-form": "2.*" } }
Then run composer install
or composer update
.
Now you can use the autoloader, and you will have access to the library:
<?php require 'vendor/autoload.php';
Alternative method (not recommended)
- Download the latest release
- Put the files in a folder that is autoloaded, or
inclure
orrequire
them
However be sure to come back regulary and check for updates.
Documentation
Complete doc is available in the wiki.
Contribution
Feel free to contribute! Just create a new issue or a new pull request.
License
This library is released under the MIT License.