本文整理汇总了PHP中Validate::run方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::run方法的具体用法?PHP Validate::run怎么用?PHP Validate::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::run方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loginAction
public function loginAction()
{
$userInfo = Session::get('user');
if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
URL::redirect('admin', 'index', 'index');
}
$this->_templateObj->setFolderTemplate('admin/main/');
$this->_templateObj->setFileTemplate('login.php');
$this->_templateObj->setFileConfig('template.ini');
$this->_templateObj->load();
$this->_view->_title = 'Login';
if (@$this->_arrParam['form']['token'] > 0) {
$validate = new Validate($this->_arrParam['form']);
$username = @$this->_arrParam['form']['username'];
$password = md5(@$this->_arrParam['form']['passwd']);
$query = "SELECT `id` FROM `user` WHERE `username` = '{$username}' AND `password` = '{$password}'";
$validate->addRule('username', 'existRecord', array('database' => $this->_model, 'query' => $query));
$validate->run();
if ($validate->isValid() == true) {
$infoUser = $this->_model->infoItem($this->_arrParam);
$arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
Session::set('user', $arraySession);
URL::redirect('admin', 'index', 'index');
} else {
$this->_view->errors = $validate->showErrors();
}
}
$this->_view->render('index/login', true);
}
示例2: loginAction
public function loginAction()
{
$userInfo = Session::get('user');
if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
URL::redirect('default', 'user', 'index');
}
$this->_view->_title = 'Login';
if (@$this->_arrParam['form']['token'] > 0) {
$validate = new Validate($this->_arrParam['form']);
$email = $this->_arrParam['form']['email'];
$password = md5($this->_arrParam['form']['password']);
$query = "SELECT `id` FROM `user` WHERE `email` = '{$email}' AND `password` = '{$password}'";
$validate->addRule('email', 'existRecord', array('database' => $this->_model, 'query' => $query));
$validate->run();
if ($validate->isValid() == true) {
$infoUser = $this->_model->infoItem($this->_arrParam);
$arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
Session::set('user', $arraySession);
URL::redirect('default', 'user', 'index');
} else {
$this->_view->errors = $validate->showErrorsPublic();
}
}
$this->_view->render('index/login');
}
示例3: validate
/**
* 验证数据
* @param $source
* @param $rules
* @return $this
*/
public static function validate($source, $rules)
{
$Validate = new Validate($source);
$Validate->addRules($rules);
$error = $Validate->run();
$source = $Validate->source;
return ['error' => $error, 'source' => $source];
}
示例4: validator
public function validator($data, $rules, $redirect_error = '')
{
$Validate = new Validate();
$validation = $Validate->run($_REQUEST, $rules);
if (is_array($validation)) {
return Redirect::action($redirect_error)->with('validation', $validation);
}
}
示例5: form
/**
* Shorthand method for inline validation
*
* @param array $data The data to be validated
* @param array $validators The validate validators
* @return mixed True(boolean) or the array of error messages
*/
public static function form(array $data, array $validators)
{
$validate = new Validate();
$validate->validation_rules($validators);
if ($validate->run($data) === false) {
return $validate->get_readable_errors(false);
} else {
return true;
}
}
示例6: formAction
public function formAction()
{
$this->_view->_title = 'User : Add';
$this->_view->slbGroup = $this->_model->itemInSelectBox($this->_arrParam);
if (isset($this->_arrParam['id'])) {
$this->_view->_title = 'User : Edit';
$this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
if (empty($this->_arrParam['form'])) {
URL::redirect('admin', 'user', 'index');
}
}
if (@$this->_arrParam['form']['token'] > 0) {
$task = 'add';
$requirePass = true;
$queryUserName = "SELECT `id` FROM `" . TBL_USER . "` WHERE `username` = '{$this->_arrParam['form']['username']}'";
$queryEmail = "SELECT `email` FROM `" . TBL_USER . "` WHERE `email` = '{$this->_arrParam['form']['email']}'";
if (isset($this->_arrParam['form']['id'])) {
$task = 'edit';
$requirePass = false;
$queryUserName .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'";
$queryEmail .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'";
}
$validate = new Validate($this->_arrParam['form']);
$validate->addRule('username', 'string-notExistRecord', array('database' => $this->_model, 'query' => $queryUserName, 'min' => 3, 'max' => 25))->addRule('email', 'email-notExistRecord', array('database' => $this->_model, 'query' => $queryEmail))->addRule('password', 'password', array('action' => $task), $requirePass)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('group_id', 'status', array('deny' => array('default')));
$validate->run();
$this->_arrParam['form'] = $validate->getResult();
if ($validate->isValid() == false) {
$this->_view->errors = $validate->showErrors();
} else {
$task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
// Insert to Database
$id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
$type = $this->_arrParam['type'];
if ($type == 'save-close') {
URL::redirect('admin', 'user', 'index');
}
if ($type == 'save-new') {
URL::redirect('admin', 'user', 'form');
}
if ($type == 'save') {
URL::redirect('admin', 'user', 'form', array('id' => $id));
}
}
}
$this->_view->arrParam = $this->_arrParam;
$this->_view->render('user/form', true);
}
示例7: formAction
public function formAction()
{
$this->_view->_title = 'Book : Add';
$this->_view->slbCategory = $this->_model->itemInSelectBox($this->_arrParam);
if (!empty($_FILES)) {
$this->_arrParam['form']['picture'] = $_FILES['picture'];
}
if (isset($this->_arrParam['id'])) {
$this->_view->_title = 'Book : Edit';
$this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
if (empty($this->_arrParam['form'])) {
URL::redirect('admin', 'book', 'index');
}
}
if (@$this->_arrParam['form']['token'] > 0) {
$task = 'add';
if (isset($this->_arrParam['form']['id'])) {
$task = 'edit';
}
$validate = new Validate($this->_arrParam['form']);
$validate->addRule('name', 'string', array('min' => 1, 'max' => 255))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('special', 'status', array('deny' => array('default')))->addRule('category_id', 'status', array('deny' => array('default')))->addRule('sale_off', 'int', array('min' => 0, 'max' => 100))->addRule('price', 'int', array('min' => 1000, 'max' => 1000000));
$validate->run();
$this->_arrParam['form'] = $validate->getResult();
if ($validate->isValid() == false) {
$this->_view->errors = $validate->showErrors();
} else {
$task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
// Insert to Database
$id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
$type = $this->_arrParam['type'];
if ($type == 'save-close') {
URL::redirect('admin', 'book', 'index');
}
if ($type == 'save-new') {
URL::redirect('admin', 'book', 'form');
}
if ($type == 'save') {
URL::redirect('admin', 'book', 'form', array('id' => $id));
}
}
}
$this->_view->arrParam = $this->_arrParam;
$this->_view->render('book/form', true);
}
示例8: formAction
public function formAction()
{
$this->_view->_title = 'User Category : Add';
if (!empty($_FILES)) {
$this->_arrParam['form']['picture'] = $_FILES['picture'];
}
if (isset($this->_arrParam['id'])) {
$this->_view->_title = 'User Category : Edit';
$this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
if (empty($this->_arrParam['form'])) {
URL::redirect('admin', 'category', 'index');
}
}
if (@$this->_arrParam['form']['token'] > 0) {
/*echo '<pre>';
print_r($this->_arrParam);
echo '</pre>';
die("Function die is called");*/
$validate = new Validate($this->_arrParam['form']);
$validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false);
$validate->run();
$this->_arrParam['form'] = $validate->getResult();
if ($validate->isValid() == false) {
$this->_view->errors = $validate->showErrors();
} else {
echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
// Insert to Database
$id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
$type = $this->_arrParam['type'];
if ($type == 'save-close') {
URL::redirect('admin', 'category', 'index');
}
if ($type == 'save-new') {
URL::redirect('admin', 'category', 'form');
}
if ($type == 'save') {
URL::redirect('admin', 'category', 'form', array('id' => $id));
}
}
}
$this->_view->arrParam = $this->_arrParam;
$this->_view->render('category/form', true);
}
示例9: login
public function login()
{
if (Session::get('loggedIn') == true) {
$this->redirect('group', 'index');
}
if (isset($_POST['submit'])) {
$source = array('username' => $_POST['username']);
$validate = new Validate($source);
$query = "SELECT `id` FROM `user` WHERE `nickname` = '{$_POST['username']}' AND `position` = '{$_POST['password']}'";
$validate->addRule('username', 'existRecord', array('database' => $this->db, 'query' => $query));
$validate->run();
$error = $validate->getError();
if ($validate->isValid() == true) {
Session::set('loggedIn', true);
$this->redirect('group', 'index');
} else {
$this->view->errors = $validate->showErrors();
}
}
$this->view->render('user/login');
}
示例10: postPassword
public function postPassword()
{
$pass = $_REQUEST['user_password'];
$Validate = new Validate();
$rules = array('user_password' => array('reqd' => 'Please provide a password', 'min[6]' => 'Your selected password must be at least 6 characters'));
$validation = $Validate->run($_REQUEST, $rules);
if (is_array($validation)) {
return Redirect::route('Password')->with('validation', $validation);
}
if ($_REQUEST['user_password'] != $_REQUEST['confirm_user_password']) {
return Redirect::back()->with('error', 'The two passwords did not match. Please try again.');
}
$this_user = Session::get('user');
$this_user = array_pop($this_user);
$this_user = (array) $this_user;
//pre('first password is ' . $this_user['user_password']);
$this_user['user_password'] = $_REQUEST['user_password'];
//pre('changed to raw ' . $this_user['user_password']);
User::addUserOfType($this_user);
return Redirect::to('redirect');
}
示例11: indexAction
public function indexAction()
{
$this->_view->_title = 'Login';
$userInfo = Session::get('user');
if (@$this->_arrParam['loginForm']['token'] > 0) {
$validate = new Validate($this->_arrParam['loginForm']);
$username = @$this->_arrParam['loginForm']['username'];
$password = md5(@$this->_arrParam['loginForm']['password']);
$query = "SELECT `id` FROM `user` WHERE `nickname` = '{$username}' AND `password` = '{$password}'";
$validate->addRule('username', 'existRecord', array('database' => $this->_model, 'query' => $query));
$validate->run();
if ($validate->isValid() == true) {
$infoUser = $this->_model->infoItem($this->_arrParam);
$arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'admin_control' => $infoUser['admin_control']);
Session::set('user', $arraySession);
URL::redirect(URL::createLink('default', 'index', 'index'));
} else {
$this->_view->errors = $validate->showErrors(false);
}
}
$this->_view->render('login/index', true);
}
示例12: formAction
public function formAction()
{
$this->_view->_title = 'Category Manager : Add';
if (isset($this->_arrParam['id'])) {
$this->_view->_title = 'Category Manager : Edit';
$this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
if (empty($this->_arrParam['form'])) {
URL::redirect(URL::createLink('admin', 'category', 'index'));
}
}
if (@$this->_arrParam['form']['token'] > 0) {
$validate = new Validate($this->_arrParam['form']);
$validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')));
$validate->run();
$this->_arrParam['form'] = $validate->getResult();
if ($validate->isValid() == false) {
$this->_view->errors = $validate->showErrors();
} else {
echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
// Insert to Database
$id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
$type = $this->_arrParam['type'];
if ($type == 'save-close') {
URL::redirect(URL::createLink('admin', 'category', 'index'));
}
if ($type == 'save-new') {
URL::redirect(URL::createLink('admin', 'category', 'form'));
}
if ($type == 'save') {
URL::redirect(URL::createLink('admin', 'category', 'form', array('id' => $id)));
}
}
}
$this->_view->arrParam = $this->_arrParam;
$this->_view->render('category/form', true);
}
示例13: json_encode
<?php
require_once "class/Validate.class.php";
$flagType = 'error';
$error = '';
$source = array('name' => $_POST['name'], 'email' => $_POST['email'], 'message' => $_POST['message'], 'file' => $_FILES['attach']);
$validate = new Validate($source);
$validate->addRule('name', 'string', array('min' => 2, 'max' => 50))->addRule('email', 'email')->addRule('message', 'string', array('min' => 5, 'max' => 500))->addRule('file', 'file', array('extension' => array('png', 'jpg'), 'min' => 50, 'max' => 9000000), false);
$validate->run();
if ($validate->isValid() == false) {
$error = $validate->getError();
} else {
$flagType = 'success';
}
$response = array('type' => $flagType, 'message' => $error);
echo json_encode($response);
示例14: Validate
*/
$fields = new Validate();
/**
* the add method creates a field usually used by a form builder
* upon creation of the field, validation methods can be chained via the addRule() method
*
* @param string Name of field
* @param string Type of field
* @param string Human readable field name
* @param boolean Is the field required
* @param string Value of field
*/
$fields->add('name', 'text', 'Full Name', 1, 'Gregory Croniser')->addRule('minLength', ['length' => 4])->addRule('maxLength', ['length' => 32]);
$fields->add('email', 'email', 'Email', 0, 'croniser@gmail.com')->addRule('email');
$fields->add('phone', 'phone', 'Phone Number', 1, '3153981146')->addRule('numeric');
/**
* run validations
*/
$errorList = $fields->run();
/**
* output validation results
*/
if (count($errorList)) {
echo '<ul style="color: red;">';
foreach ($errorList as $error) {
echo "<li>{$error}</li>";
}
echo '</ul>';
} else {
echo '<p style="color: green;">All fields pass validation.<br />Change field values to test validation</p>';
}