rlanvin/php-form

Lightweight form validation library for PHP

v2.0.1 2016-04-11 09:58 UTC

This package is auto-updated.

Last update: 2024-10-22 04:01:00 UTC


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.

Build Status Latest Stable Version

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

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 or require 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.