PHP code example of ikkez / f3-validation-engine
1. Go to this page and download the library: Download ikkez/f3-validation-engine 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/ */
ikkez / f3-validation-engine example snippets
$validation = \Validation::instance();
$validation->onError(function($text,$key) {
\Base::instance()->set('error.'.$key, $text);
\Flash::instance()->addMessage($text,'danger');
});
\Validation::instance()->loadLang();
protected $fieldConf = [
'username' => [
'type' => Schema::DT_VARCHAR128,
'filter' => 'trim',
'validate' => 'ail_host',
],
];
$valid = $validation->validateCortexMapper($mapper);
namespace Model;
class User extends \DB\Cortex {
use \Validation\Traits\CortexTrait;
// ...
}
$data = [
'username' => 'Jonny',
'email' => '[email protected] ',
];
$rules = [
'username' => [
'filter' => 'trim',
'validate' => 'ata);
'foo' => [
'filter' => 'trim|base64_decode',
'validate' => '
'foo' => [
'validate' => ' 'bar' => 2
]
]
'foo' => [
'validate' => ' 'bar' => ['validate', 'min_numeric,2']
]
]
'validate_depends' => [
'bar' => ['call', function($value,$input) { return (bool) $value % 3 }]
]
'foo' => [
'validate_level'=>2,
'validate' => '
$validation->validateCortexMapper($mapper, $level);
// OR
$validation->validate($rules, $data, $level);
'contact' => [
'type' => self::DT_JSON,
'validate_array' => [
'name' => ['validate'=>'red'],
'zip' => ['validate'=>'
'partners' => [
'type' => self::DT_JSON,
'validate_nested_array' => [
'name' => ['validate'=>''filter'=>'upload'],
]
]
'foo' => [
'type' => Schema::DT_VARCHAR128,
'item' => [
'one',
'two',
'three',
]
]
\Validation::instance()->setStringifyModel(function($mapper) {
return implode('.',array_map('lcfirst',explode('\\',get_class($mapper))));
});
$valid = $userModel->validate();
if (!$userModel->foo1 && !$userModel->foo2) {
\Validation::instance()->emitError('foo','
\Validation::instance()->emitError('phone_mail_copy',' 'model.employerprofile.phone_mail_orig', // context label
]);
if ($f3->get('POST.password') !== $f3->get('POST.password2')) {
// The {0} field does not equal {1} field
\Validation::instance()->emitError(['password','Password repeat'],'equalsfield','model.user');
}
\Validation::instance()->addValidator('is_one', function($field, $input, $param=NULL) {
return $input[$field] === 1;
}, 'The field "{0}" must be 1');
\Validation::instance()->addFilter('nl2br',function($value,$params=NULL) {
return nl2br($value);
});
$validator = \Validation::instance();
$validator->addValidator('is_one','App\MyValidators->is_one');
$validator->addFilter('nl2br','App\MyFilters->nl2br');