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.
// 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.
- 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.
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';
- 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.
Complete doc is available in the wiki.
Feel free to contribute! Just create a new issue or a new pull request.
This library is released under the MIT License.