1. Go to this page and download the library: Download grithin/php-conform library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
grithin / php-conform example snippets
# Simplest example
$Conform = new Conform(['age'=>' 10 ']);
if($conformed = $Conform->get(['age'=>'f.int'])){
# in converting age to in, Conform has stripped the spaces
echo $conformed['age']; # => 10
}
# You can set the input either at construction or after
$Conform = new Conform(['name'=>'bob']);
$Conform->input(['name'=>'sue']);
# if you do not provide an input on the construction (input value is false), Conform will use $_GET and $_POST as defaults, with $_POST overwriting colliding $_GET keys
$_POST = ['name'=>'bob'];
$Conform = new Conform();
$Conform->input(); # > ['name'=>'bob']
# if you want to set the input to the default input after construction, you can use the `request_input` method
$Conform->input(Conform::request_input());
# the request_input has some additional logic about pulling input from the request that
$Conform = new Conform(['age'=>'bob']);
$rules = ['age'=>'f.digits, v.int'];
if($conformed = $Conform->get($rules)){
# ...
}else{
echo 'did not validate';
}
# > did not validate
# a closure
$Conform->conformer_add('upper', function($x){ return strtoupper($x);});
$rules = ['name'=>'upper'];
# an object with methods
$Conform->conformer_add('f', new \Grithin\Conform\Filter);
$rules = ['id'=>'f.int'];
# a function reference
$Conform->conformer_add('upper', 'strtoupper');
$rules = ['name'=>'upper']; # note, this will error b/c strtoupper does not expect 2 parameters ($Conform instance is passed as the last parameter)
//...
# get all the errors for the field "year"
$Conform->field_errors('year');
# get all the errors for the fields "year" and "number"
$Conform->fields_errors(['year', 'number']);
$auth = function($v, $Conform){
$query = ['id'=>$Conform->output['id'], 'password'=>$conform->input['password']]
if(!Db::check($query)){
$Conform->error('Password and id did not match');
}
return $v;
};