Bouncer is a library that allows you to flexible, quickly and easy to use filter and validate HTML forms.
Examples Β· Open issue Β· Report bug
- Features
- Quick start
- API
- License
- Changelog
- Release notes
- Future release plans
- Known questions
- Credits
- π It is very easy to use and does not require any dependency.
- π The entire form can be validate at the same time or optionally particular fields can also be validate.
- π― You do not need to check the validity of each field separately. Bouncer keeps track of the validity of the entire form for you.
- π οΈ It has predefined error messages for each validation method and these messages can be changed from the options.
- βοΈ You can create custom validation and filter methods for each field.
- π You can define custom error messages for each field.
- π Supports error messages (value, parameters, field label if predefined and rule title) variables.
- π Includes more than 30 different built-in methods for validation and filtering.
- β»οΈ It has the ability to automatically add form data submitted with
$_POST
and$_GET
requests. Thus, you do not need to define the form fields one by one. - π² It is completely free to use and open source.
Bouncer can be used either with or without Composer.
The preferred way to use Bouncer is with Composer. Execute the following command to install this package as a dependency in your project:
composer require bozworks/bouncer.php
<?php
use Boz\Bouncer as Bouncer;
//Load Composer's autoloader
require 'vendor/autoload.php';
new Bouncer();
Bouncer does not have any dependencies. Therefore, you can download and include it directly in your file and start using it:
<?php
require 'class.bouncer.php';
use Boz\Bouncer as Bouncer;
new Bouncer();
In the example below, let's basically verify a user's session information with Bouncer.
<?php
require 'class.bouncer.php';
use Boz\Bouncer as Bouncer;
$bouncer = new Bouncer(array(
'useremail' => 'john@example.tld',
'password' => '12345',
'expiry' => '3 day'
));
$bouncer
->name('useremail')
->required()
->email()
->name('password')
->required()
->callback(function($password){ return ('12345' === $password); })
->name('expiry')
->required()
->minlength(5)
->endswith('day')
->validate(true);
if($bouncer->get('valid') === 1) {
openSession(
$bouncer->get('value', 'useremail'),
$bouncer->get('value', 'expiry')
);
echo '<div role="alert" class="msg success">Successfully Logged In</div>';
} else {
foreach($bouncer->get('errors') as $field => $errors) {
foreach ($errors as $rule => $error) {
echo '<div role="alert" class="msg error">' . $error . '</div>';
}
}
}
You can find a complete guide example in the examples folder.
Bouncer's code is released under the MIT License, the art and docs are released under Creative Commons. (MIT AND CC-BY-4.0)
- Automatically print the error messages based on the field.
- Added some improvements and examples.
See the change log.
- Multiple rule support.
- New methods "contains" and "notcontains".
See the change log.
- Yes Bouncer is capable of handling multiple rules.
- Yes Bouncer is capable of handling multiple callbacks.
- No, for now it can only be defined once from the same rule. Bouncer is planned to have this ability in the future.
This repository is inspired by bouncer.js
Get the JavaScript version developed by @cferdinandi. Bouncer.js