PHPackages                             rlanvin/php-form - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. rlanvin/php-form

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

rlanvin/php-form
================

Lightweight form validation library for PHP

v2.0.1(10y ago)3476.1k↓38.2%7MITPHPPHP &gt;=5.4.0

Since Oct 12Pushed 5y ago5 watchersCompare

[ Source](https://github.com/rlanvin/php-form)[ Packagist](https://packagist.org/packages/rlanvin/php-form)[ Docs](https://github.com/rlanvin/php-form)[ RSS](/packages/rlanvin-php-form/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)DependenciesVersions (7)Used By (0)

PHP Form
========

[](#php-form)

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.

[![Build Status](https://camo.githubusercontent.com/4295a68b17986d89476ebbe7a4fa0506d967ac1d33749587e88becf2a60a9761/68747470733a2f2f7472617669732d63692e6f72672f726c616e76696e2f7068702d666f726d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rlanvin/php-form)[![Latest Stable Version](https://camo.githubusercontent.com/c0dfe3d6e52f303464cb9678cea0e4a492085f0d72cf0cb503aaaaff075c0b4c/68747470733a2f2f706f7365722e707567782e6f72672f726c616e76696e2f7068702d666f726d2f762f737461626c65)](https://packagist.org/packages/rlanvin/php-form)

Basic example
-------------

[](#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](https://github.com/rlanvin/php-form/wiki).

Requirements
------------

[](#requirements)

- PHP &gt;= 5.4
- [`mbstring` extension](http://www.php.net/manual/en/book.mbstring.php)
- [`intl` extension](http://php.net/manual/en/book.intl.php) recommended to validate numbers in local format

If you are stuck with PHP 5.3, you may still use [version 1.1](https://github.com/rlanvin/php-form/releases/tag/v1.1.0).

Installation
------------

[](#installation)

The recommended way is to install the lib [through Composer](http://getcomposer.org/).

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:

```
