1. Go to this page and download the library: Download xphoenyx/valify 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/ */
xphoenyx / valify example snippets
$validator = new Validator();
use valify\Validator;
use valify\Validator;
class Model {
/* ... */
protected $validator;
// Your rules
public $rules = [];
// Here is stored $_POST, for example
public $data = [];
function __construct() {
/* ... */
$this->validator = new Validator();
/* ... */
}
/*
* Your other methods
*/
public function validate() {
return $this->validator
->setRules($this->rules)
->loadData($this->data)
->validate();
}
public function getErrors() {
return $this->validator->getErrors();
}
}
$rules = [
[['username', 'password'], 'string', 'max'=>10],
['email', 'email', 'message'=>'Please provide a valid email'],
['remember_me', 'boolean']
/* ... */
];
['email', 'email', 'message'=>'{value} for attribute "{attribute}" is not a valid email'],