1. Go to this page and download the library: Download grithin/phpinput 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 / phpinput example snippets
use \Grithin\Input;
$in = ['bob'=>'sucks'];
$input = new Input(['in'=>$in]);
#validate that the bob value is a float
$rules = ['bob'=>'v.isFloat'];
if($input->handle($rules)){
die("Yay!");
}else{
echo 'uh oh...';
\Grithin\Debug::quit($input->errors);
}
/*
uh oh...
[base:index.php:19] 1: [
0 : [
'type' : 'isFloat'
'fields' : [
0 : 'bob'
]
]
]
*/
use \Grithin\Input;
$passingInput = [];
$passingInput[1] = [
'phone'=>'my phone number is (555) 555-5555.',
'appointment_time' => 'August 8, 2020',
'comment' => ' bob is a crazy '
];
$passingInput[2] = [
'phone'=>'my phone number is (555) 555-5555.',
'comment' => ' bob is a crazy '
];
#validate that the bob value is a float
$rules = [
'phone'=>'v.phone',
'appointment_time'=>'?!v.filled,v.date,f.datetime', #< '?' means optional, '!' means stop of not validated
'comment' => 'f.trim'
];
$input = new Input(['in'=>$passingInput[1]]);
$input->handle($rules);
\Grithin\Debug::out($input->in);
/*
[base:index.php:34] 1: [
'phone' : '5555555555'
'appointment_time' : '2020-08-08 00:00:00'
'comment' : 'bob is a crazy'
]*/
$input = new Input(['in'=>$passingInput[2]]);
$input->handle($rules);
\Grithin\Debug::out($input->in);
/*
[base:index.php:45] 2: [
'phone' : '5555555555'
'comment' : 'bob is a crazy'
]
*/
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.