/** * Default validation field * if validation failed method * throw validation exception */ public function validate($value) { $this->validation = new Validation(array($this->get_name() => $value)); //$this->validation->label($this->get_name(), $this->get_name()); if ($this->item['notnull']) { if ($value == null) { $this->validation->rule($this->get_name(), 'not_empty'); } } if (!$this->validation->check()) { throw new Validation_Exception($this->validation); } return $this->validation; }
public function action_show() { $arr = []; //Получаем данные из формы if (isset($_POST['submit'])) { //Проверяем введенные данные на корректность $post = new Validation($_POST); $post->rule('prime', 'not_empty')->rule('prime', 'numeric'); if ($post->check()) { $max = $_POST['prime']; $arr = Controller_PrimeNumber::getPrime($max); Controller_DataArchive::saveDB($max, $arr); } else { $errors = $post->errors('comments'); } } //Подготавливаем данные для вида $view = View::factory('index'); if (isset($errors)) { $view->err = $errors; } else { if (!empty($arr)) { $view->arr = $arr; } } $this->response->body($view); }
public function validate(CM_Form_Abstract $form) { $values = array(); foreach ($form->get_values() as $name => $value) { $values[$name] = $value->get_raw(); $this->_validation->label($name, $form->get_field($name)->get_label()); } // Validation только read-only, поэтому создаем новый объект $this->_validation = $this->_validation->copy($values); if ($this->_validation->check()) { return TRUE; } foreach ($this->_validation->errors('validation') as $name => $error) { $form->set_error($name, $error); } return FALSE; }
public function submit() { list($this->validationFlag, $this->validation) = Validation::check(array('nombre' => 'required')); if ($this->validationFlag) { $nombre = Request::getPost('nombre'); Db::insert('empresas', array('nombre' => $nombre, 'fecha_creacion' => time())); Response::setRedirect('/personas'); } }
/** * @param bool $throwException * * @throws RestfulAPI_Exception_422 * @return bool */ public function check($throwException = TRUE) { $result = parent::check(); if (!$result && $throwException) { // var_dump($this->data(), $this->getRules()); // die(); throw new RestfulAPI_Exception_422($this->errors()); } return $result; }
public function submit() { list($this->validationFlag, $this->validation) = Validation::check(array('nombre' => 'required', 'apellido' => 'required')); if ($this->validationFlag) { $nombre = Request::getPost('nombre'); $apellido = Request::getPost('apellido'); $correo = Request::getPost('correo'); $cargo = Request::getPost('cargo'); Db::insert('personas', array('id_empresas' => $this->idEmpresas, 'nombre' => $nombre, 'apellido' => $apellido, 'correo' => $correo, 'cargo' => $cargo, 'fecha_creacion' => time())); Response::setRedirect("/empresas/{$this->idEmpresas}/personas"); } }
protected function _login(Validation $validation, $remember) { if ($validation->check()) { Observer::notify('login_before', $validation); if (Auth::instance()->login($validation[$this->get('login_field')], $validation[$this->get('password_field')], $remember)) { Observer::notify('login_success', $validation[$this->get('login_field')]); HTTP::redirect($this->get_next_url()); } else { Observer::notify('login_failed', $validation); Messages::errors(__('Login failed. Please check your login data and try again.')); } } HTTP::redirect(Request::current()->referrer()); }
public function action_index() { $installation_status = Kohana::$config->load('install.status'); switch ($installation_status) { case NOT_INSTALLED: if (!$this->check_installation_parameters()) { //$data['title']=__('Installation: something wrong'); // $this->data=Arr::merge($this->data, Helper::get_db_settings()); $this->data = Arr::merge($this->data, get_object_vars($this->install_config)); $res = View::factory('install_form', $this->data)->render(); //Model::factory('model_name')->model_method( $data ); } else { $_post = Arr::map('trim', $_POST); $post = new Validation($_post); $post->rule('db_path', 'not_empty')->rule('db_name', 'not_empty')->rule('db_login', 'not_empty')->rule('installer_login', 'not_empty')->rule('installer_password', 'not_empty'); if ($post->check()) { Helper::save_install_settings($post); if (!Model::factory('install')->install($err_list)) { Helper::set_installation_status(NOT_INSTALLED); foreach ($err_list as $e) { $this->data['errors'][] = $e['error']; } $res = View::factory('installing', $this->data)->render(); } else { $res = View::factory('installing_ok', $this->data)->render(); } } else { // Кажется что-то случилось //$data['title']=__('Installation: something wrong'); $this->data['errors'] = $post->errors('validation'); $res = View::factory('install_form', $this->data)->render(); } } break; case INSTALLING: $res = View::factory('installing')->render(); break; case INSTALLED: // $res = View::factory('/')->render(); $this->redirect('/'); break; default: // $res = View::factory('/')->render(); $this->redirect('/'); break; } // Save result / Сохраняем результат $this->_result = $res; }
public function validate($data) { $val = new Validation($data); foreach ($this->validator as $key => $rules) { foreach ($rules as $rule => $value) { if (is_numeric($rule)) { $val->rule($key, $value); } else { $val->rule($key, $rule, $value); } } } $val->check(); return $val->errors(); }
public function submit() { $this->usuario = Request::getPost('usuario'); $this->contrasena = md5(Request::getPost('contrasena')); $this->recordar = Request::getPost('recordar', 0); list($this->validationFlag, $this->validation) = Validation::check(array('usuario' => 'required', 'contrasena' => 'required')); if ($this->validationFlag) { $idPersonas = Db::one("SELECT personas.id_personas\n FROM personas\n WHERE personas.usuario = '{$this->usuario}'\n AND personas.contrasena = '{$this->contrasena}'\n LIMIT 1"); if ($idPersonas) { Session::unregister(); Session::register($this->usuario, $this->contrasena, $this->recordar == 1); Response::setRedirect('/'); } $this->validationFlag = false; } }
public function index() { //add params $user = new User(); if ($user->isLoggedIn()) { Redirect::to('account'); //$this->view('user/index', ['flash' => '', 'name' => $user->data()->name]); } else { if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validation = $validate->check($_POST, array('username' => array('required' => true), 'password' => array('required' => true))); if ($validation->passed()) { $user = new User(); $remember = Input::get('remember') === 'on' ? true : false; $login = $user->login(Input::get('username'), Input::get('password'), $remember); if ($login) { //login success Session::flash('account', 'You are now logged in'); Redirect::to('account'); } else { //login failed $error_string = 'Username or passowrd incorrect<br>'; $this->view('login/failed', ['loggedIn' => 2, 'page_heading' => 'Login', 'errors' => $error_string]); } } else { $error_string = ''; //there were errors //Create a file that prints errors foreach ($validation->errors() as $error) { $error_string .= $error . '<br>'; } $this->view('login/failed', ['loggedIn' => 0, 'page_name' => 'Login', 'errors' => $error_string]); } } else { //token did not match so go back to login page $this->view('login/index', ['loggedIn' => 2, 'page_name' => 'Login']); } } else { $this->view('login/index', ['loggedIn' => 2, 'page_name' => 'Login']); } } }
public function submit() { if (Request::hasPost('guardar')) { list($this->validationFlag, $this->validation) = Validation::check(array('nombre' => 'required', 'apellido' => 'required')); if ($this->validationFlag) { $nombre = Request::getPost('nombre'); $apellido = Request::getPost('apellido'); $correo = Request::getPost('correo'); $cargo = Request::getPost('cargo'); $telOficina = Request::getPost('tel_oficina'); $telOficinaInt = Request::getPost('tel_oficina_int'); $telCelular = Request::getPost('tel_celular'); $telFax = Request::getPost('tel_fax'); $telCasa = Request::getPost('tel_casa'); Db::update('personas', array('nombre' => $nombre, 'apellido' => $apellido, 'correo' => $correo, 'cargo' => $cargo, 'tel_oficina' => $telOficina, 'tel_oficina_int' => $telOficinaInt, 'tel_celular' => $telCelular, 'tel_fax' => $telFax, 'tel_casa' => $telCasa, 'fecha_modificacion' => time()), "id_personas = '{$this->idPersonas}'"); Response::setRedirect("/personas/{$this->idPersonas}"); } } }
public function submit() { if (Request::hasPost('guardar')) { list($this->validationFlag, $this->validation) = Validation::check(array('nombre' => 'required')); if ($this->validationFlag) { $nombre = Request::getPost('nombre'); $direccion1 = Request::getPost('direccion_1'); $direccion2 = Request::getPost('direccion_2'); $ciudad = Request::getPost('ciudad'); $estado = Request::getPost('estado'); $codPostal = Request::getPost('cod_postal'); $idPaises = Request::getPost('id_paises'); $web = Request::getPost('web'); $telOficina = Request::getPost('tel_oficina'); $telFax = Request::getPost('tel_fax'); Db::update('empresas', array('nombre' => $nombre, 'direccion_1' => $direccion1, 'direccion_2' => $direccion2, 'ciudad' => $ciudad, 'estado' => $estado, 'cod_postal' => $codPostal, 'id_paises' => $idPaises, 'web' => $web, 'tel_oficina' => $telOficina, 'tel_fax' => $telFax, 'fecha_modificacion' => time()), "id_empresas = '{$this->idEmpresas}'"); Response::setRedirect("/empresas/{$this->idEmpresas}"); } } }
public function action_upload() { $md5 = md5($_FILES['image']['tmp_name']); $file = $md5 . '_' . time() . '.' . pathinfo($_FILES['image']['name'])['extension']; $fileValidation = new Validation($_FILES); $fileValidation->rule('image', 'upload::valid'); $fileValidation->rule('image', 'upload::type', array(':value', array('jpg', 'png'))); if ($fileValidation->check()) { if ($path = Upload::save($_FILES['image'], $file, DIR_IMAGE)) { ORM::factory('File')->set('sid', $this->siteId)->set('name', $_FILES['image']['name'])->set('path', $file)->set('md5', $md5)->set('types', Model_File::FILE_TYPES_IMG)->set('created', time())->set('updated', time())->save(); $site = ORM::factory('Site')->where('id', '=', $this->siteId)->where('uid', '=', $this->user['id'])->find(); $site->set('logo', $file)->set('updated', time())->save(); jsonReturn(1001, '上传成功!', '/media/image/data/' . $file); } else { jsonReturn(4444, '图片保存失败'); } } else { jsonReturn(4444, '图片上传失败'); } }
public static function registration($formAttribues) { unset($_SESSION['errors']); $email = $formAttribues['email']; $password = $formAttribues['password']; $name = $formAttribues['name']; $password_compare = $formAttribues['password_compare']; $username = $formAttribues['username']; $attributes = ['name' => $name, 'email' => $email, 'password' => $password, 'password_compare' => $password_compare, 'username' => $username]; $rules = [[['email', 'password', 'name', 'password_compare', 'username'], 'required'], [['name'], 'type', 'type' => 'string', 'min' => 6, 'max' => 32], [['email'], 'email'], [['password'], 'type', 'type' => 'string', 'min' => 4, 'max' => 32], [['password_compare'], 'compare', 'attribute' => 'password', 'message' => 'Повтор пароля повинен співпадати з паролем'], [['email', 'username'], 'unique', 'tableName' => 'users']]; $validation = new Validation(); $validation->check($attributes, $rules); if (empty($validation->errors)) { $row = Db::insert('users', ['email' => $email, 'password' => md5($password), 'name' => $name, 'username' => $username]); setFlash('sucess', 'Бла бла бла ...'); return true; } $_SESSION['errors'] = $validation->errors; return false; }
public function action_uploadavatar() { $filename = time() . '_' . $_FILES['image']['name']; $file_validation = new Validation($_FILES); $file_validation->rule('image', 'upload::valid'); $file_validation->rule('image', 'upload::type', array(':value', array('jpg', 'png', 'gif', 'jpeg'))); if ($file_validation->check()) { if ($path = Upload::save($_FILES['image'], $filename, DIR_IMAGE)) { $image = CacheImage::instance(); $src = $image->resize($filename, 100, 100); $user = Auth::instance()->get_user(); $user->avatar = $filename; $user->save(); $json = array('success' => 1, 'image' => $src); } else { $json = array('success' => 0, 'errors' => array('image' => 'The file is not a valid Image')); } } else { $json = array('success' => 0, 'errors' => (array) $file_validation->errors('profile')); } echo json_encode($json); exit; }
public function index() { $user1 = new User(); if ($user1->isLoggedIn()) { //would you like to register a new user } else { if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validate->check($_POST, array('username' => array('min' => 2, 'max' => 20, 'required' => true, 'unique' => true), 'name' => array('min' => 2, 'max' => 50, 'required' => true), 'sirname' => array('min' => 2, 'max' => 50, 'required' => true), 'email' => array('min' => 5, 'max' => 64, 'email' => true, 'required' => true, 'unique' => true), 'date_of_birth' => array('min' => 6, 'max' => 10, 'date' => true, 'required' => true), 'password' => array('min' => 6, 'required' => true), 'password_again' => array('min' => 6, 'matches' => 'password', 'required' => true))); if ($validate->passed()) { $user = new User(); $salt = Hash::salt(32); $date_of_birth = new Date(Input::get('date_of_birth')); try { $user->create(array('username' => Input::get('username'), 'name' => Input::get('name'), 'sirname' => Input::get('sirname'), 'email' => Input::get('email'), 'dateofbirth' => $date_of_birth->format('Y-m-d H:i:s'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'joined' => date('Y-m-d H:i:s'), 'group' => 1)); Session::flash('success', 'You have been registered'); Redirect::to('home'); } catch (Exception $e) { die($e->getMessage()); } } else { $error_string = ''; //there were errors //Create a file that prints errors foreach ($validate->errors() as $error) { $error_string .= $error . '<br>'; } $this->view('register/failed', ['loggedIn' => 0, 'page_name' => 'Login Failed', 'errors' => $error_string]); } } } else { //display form page $this->view('register/register', ['register' => true, 'page_name' => 'Register', 'loggedIn' => 0]); } } }
} } else { Redirect::to('/404'); //TODO: MAKE 404 } if (!$user->isLoggedIn()) { Session::flash('error', 'It seems you are not logged in!'); Redirect::to('/'); } $db = DB::getInstance(); $q = $db->get('post', array('id', '=', escape($post_id)))->first(); if (Input::exists()) { if (Input::get('Submit')) { if (Token::check(Input::get('token'))) { $val = new Validation(); $validate = $val->check($_POST, array('title' => array('required' => true), 'content' => array('required' => true))); if ($validate->passed()) { try { $forums->createReply(array('title' => escape(Input::get('title')), 'post_id' => escape($post_id), 'content' => Input::get('content'), 'date' => date('Y-m-d- H:i:s'), 'user_id' => $user->data()->id)); Notifaction::createMessage($user->data()->username . ' posted a reply on your page', $forums->getPost2($post_id)->post_user); session::flash('complete', 'You posted your reply!'); Redirect::to('/forums/view/' . $cat . '/' . $post_id); } catch (Exception $e) { die($e->getMessage()); } } else { echo 'val not passed'; } } else { die('token failed'); }
<?php require_once '../core/init.php'; $user = new User(); if (!$user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validation = $validate->check($_POST, array('name' => array('required' => true, 'min' => 2, 'max' => 50))); if ($validation->passed()) { try { $user->update(array('name' => Input::get('name'))); Session::flash('home', 'Your details have been updated'); Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { foreach ($validation->errors() as $error) { echo $error, '<br>'; } } } } ?> <form action="" method="post"> <div class="field"> <label for="name">Name</label>
<?php if (Input::exists()) { if (token::check(Input::get('token'))) { $val = new Validation(); $validation = $val->check($_POST, array('message' => array('required' => true))); if ($validation->passed()) { foreach ($db->get('users', array('1', '=', '1'))->results() as $userAcc) { try { Notifaction::createMessage(Input::get('message'), $userAcc->id); Session::flash('complete', 'You sent a mass message!'); Redirect::to('?page=notification'); } catch (Exception $e) { } } } } } ?> <!DOCTYPE html> <html lang="en"> <head> <?php include 'inc/templates/head.php'; ?> </head> <body> <div class="col-md-3"><?php include 'inc/templates/nav.php'; ?> </div>
</div> <div class="sub-navigation"> <span> <a href="contact.php?id=<?php echo $contact->data()->id; ?> ">Cancel</a> </span> </div> </div> <?php //Validates data if (Input::exists()) { $validate = new Validation(); $validation = $validate->check($_POST, array('band' => array('max' => 64), 'first_name' => array('max' => 64), 'last_name' => array('max' => 64), 'email' => array('required' => true, 'max' => 1024, 'is_email' => true), 'phone' => array('max' => 64, 'is_numeric' => true), 'mobile' => array('max' => 64, 'is_numeric' => true), 'company' => array('max' => 64), 'add_line_1' => array('max' => 128), 'add_line_2' => array('max' => 128), 'state' => array('max' => 128), 'city' => array('max' => 128), 'post_code' => array('max' => 128, 'is_numeric' => true))); if ($validation->passed()) { $contact = new Contact(); try { //sends updated data to the database $contact->update(Input::get('id'), array('company' => Input::get('company'), 'band' => Input::get('band'), 'first_name' => Input::get('first_name'), 'last_name' => Input::get('last_name'), 'email' => Input::get('email'), 'add_line_1' => Input::get('add_line_1'), 'add_line_2' => Input::get('add_line_2'), 'state' => Input::get('state'), 'city' => Input::get('city'), 'post_code' => Input::get('post_code'), 'phone' => Input::get('phone'), 'mobile' => Input::get('mobile'), 'notes' => Input::get('notes'), 'date_modified' => date('Y-m-d H:i:s'))); Session::flash('home', 'The <a href="contact.php?id=' . Input::get('id') . '">contact</a> has been updated successfully'); Redirect::to('index.php'); } catch (Exception $e) { Session::flash('home', $e->getMessage()); Redirect::to('index.php'); exit; } } else { echo '<ul class="error">'; foreach ($validation->errors() as $error) {
/** * Tests Validation::check() * * @test * @covers Validation::check * @covers Validation::rule * @covers Validation::rules * @covers Validation::errors * @covers Validation::error * @dataProvider provider_check * @param array $array The array of data * @param array $rules The array of rules * @param array $labels The array of labels * @param boolean $expected Is it valid? * @param boolean $expected_errors Array of expected errors */ public function test_check($array, $rules, $labels, $expected, $expected_errors) { $validation = new Validation($array); foreach ($labels as $field => $label) { $validation->label($field, $label); } foreach ($rules as $field => $field_rules) { foreach ($field_rules as $rule) { $validation->rule($field, $rule[0], $rule[1]); } } $status = $validation->check(); $errors = $validation->errors(TRUE); $this->assertSame($expected, $status); $this->assertSame($expected_errors, $errors); $validation = new validation($array); foreach ($rules as $field => $rules) { $validation->rules($field, $rules); } $validation->labels($labels); $this->assertSame($expected, $validation->check()); }
<?php $user = new User(); $forums = new Forums(); if (!$user->isAdmLoggedIn() && !$user->data()->group == 3) { Session::flash('error', 'You are not admin/logged in!'); Redirect::to('/admin'); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $val = new Validation(); $validation = $val->check($_POST, array('title' => array('required' => true), 'cat_par' => array('required' => true))); if ($validation->passed()) { $parent = Input::get('cat_par') == "NULL" ? null : Input::get('cat_par'); try { $forums->createCat(array('name' => escape(Input::get('title')), 'parent' => $parent)); Session::flash('complete', 'You added a cat!'); Redirect::to('/admin'); } catch (Exception $e) { } } } } ?> <html> <head> <?php require 'inc/templates/head.php'; ?> </head> <body>
<?php if (Input::exists()) { $validate = new Validation(); $validation = $validate->check($_POST, array('category' => array('required' => true), 'label' => array('required' => true, 'min' => 2, 'max' => 50), 'title' => array('required' => true, 'min' => 2, 'max' => 50), 'slug' => array('required' => true, 'min' => 6), 'user' => array('required' => true), 'body' => array('required' => true, 'min' => 6))); //if validation has passed if ($validation->passed()) { //instantiate new user if (isset($_FILES['photo'])) { $target = "images/"; $target = $target . basename($_FILES['photo']['name']); } else { echo 'Image is not set'; } //try catch method try { //user create array DB::getInstance()->insert('pages', array('category' => Input::get('category'), 'label' => Input::get('label'), 'title' => Input::get('title'), 'slug' => Input::get('slug'), 'user' => Input::get('user'), 'photo' => Input::pic('photo'), 'body' => Input::get('body'))); if (move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //Tells you if its all ok echo "Your article has been uploaded"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } //then redirect to index and show flash message Session::flash('home', 'Post complete'); // Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); }
<img src="image/xv.png" alt="Mountain View" style="width:200px;height:80px;"> </div> <!-- Form Module--> <div class="module form-module"> <div class="toggle"> <i class="fa fa-times fa-pencil"></i> <div class="tooltip">Click Me</div> </div> <div class="form"> <h2>Login to your account</h2> <?php if (isset($_POST['btn-login'])) { if (Input::exists()) { if (Token::check(Input::get('token'))) { $validation = new Validation(); $validation->check($_POST, array('username' => array('required' => 'true'), 'password' => array('required' => 'true'))); if ($validation->passed()) { $user = new User(); $remember = Input::get('remember') === 'on' ? true : false; $login = $user->login(Input::get('username'), Input::get('password'), $remember); if ($login) { if ($user->apprved_user('approved')) { Redirect::to('adminindex.php'); } else { echo '<font color="brown"><strong>Warning!</strong>You need admin permission to log-in to this system</font>'; } } else { echo '<center><font color="red"><b>Sorry, Failed to login to the System,<br>try with Correct<br> password and username!</b></font></center>'; } echo '<br>'; } else {
<?php require_once 'core/init.php'; $user = new User(); require_once 'core/checkLogin.php'; if (!$user->isLoggedIn()) { Redirect::to('index.php'); } else { if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validation = $validate->check($_POST, array('firstname' => array('required' => true, 'min' => 2, 'max' => 50), 'lastname' => array('required' => true, 'min' => 2, 'max' => 50), 'location' => array('required' => true, 'min' => 5, 'max' => 50), 'description' => array('required' => true, 'max' => 255))); if ($validation->passed()) { try { $user->update(array('firstname' => escape(Input::get('firstname')), 'lastname' => escape(Input::get('lastname')), 'location' => escape(Input::get('location')), 'description' => escape(Input::get('description')))); Session::flash('home', 'Your information was successfully updated!'); Redirect::to('dashboard.php'); } catch (Exception $e) { die($e->getMessage()); } } } } } include 'includes/header.php'; ?> <div class="header-wrapper"> <div class="header-container"> <h3>Settings</h3> </div>
if (isset($_GET['delete']) && $_GET['delete'] == true && isset($_GET['opponentid']) && is_numeric($_GET['opponentid'])) { try { $opponentId = escape($_GET['opponentid']); $leagueOptions->deleteOpponent($opponentId); Session::flash('deleted', 'Opponent Deleted Successfully'); Redirect::to('opponents.php'); } catch (Exception $e) { die($e->getMessage()); } } else { $opponentsResults = $leagueOptions->getOpponents(); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validation = $validate->check($_POST, array('OpponentName' => array('name' => 'Opponent', 'min' => 5, 'max' => 50, 'unique' => 'opponent', 'required' => true))); if ($validation->passed()) { try { $leagueOptions->createOpponent(array('OpponentName' => Input::get('OpponentName'))); Session::flash('opponentCreated', 'Opponent created Successfully'); Redirect::to('opponents.php'); } catch (Exception $e) { die($e->getMessage()); } $displayErrors = "none"; } else { $errorDisplay = ""; $displayErrors = "block"; foreach ($validation->errors() as $error) { $errorDisplay = $errorDisplay . $error . "<br>"; }
/** * Tests Validation::check() * * @test * @covers Validation::check */ public function test_check_stops_when_error_added_by_callback() { $validation = new Validation(array('foo' => 'foo')); $validation->rule('foo', array($this, '_validation_callback'), array(':validation'))->rule('foo', 'min_length', array(':value', 20)); $validation->check(); $errors = $validation->errors(); $expected = array('foo' => array(0 => '_validation_callback', 1 => NULL)); $this->assertSame($errors, $expected); }
/** * Validates the current model's data * * @param Validation $extra_validation Validation object [Optional] * @return ORM * @throws ORM_Validation_Exception */ public function check(Validation $extra_validation = NULL) { // Determine if any external validation failed $extra_errors = ($extra_validation and !$extra_validation->check()); // Always build a new validation object $this->_validation(); // add custom rules to $this->_validation(); Module::event($this->_object_name . '_validation', $this->_validation, $extra_errors); $array = $this->_validation; if (($this->_valid = $array->check()) === FALSE or $extra_errors) { $exception = new ORM_Validation_Exception($this->errors_filename(), $array); if ($extra_errors) { // Merge any possible errors from the external object $exception->add_object('_external', $extra_validation); } // Fixed memory leak @http://dev.kohanaframework.org/issues/4286 $this->_validation = NULL; throw $exception; } // Fixed memory leak @http://dev.kohanaframework.org/issues/4286 $this->_validation = NULL; return $this; }
if (isset($_GET['delete']) && $_GET['delete'] == true && isset($_GET['locationid']) && is_numeric($_GET['locationid'])) { try { $locationId = escape($_GET['locationid']); $leagueOptions->deleteLocation($locationId); Session::flash('deleted', 'Location Deleted Successfully'); Redirect::to('locations.php'); } catch (Exception $e) { die($e->getMessage()); } } else { $locationResults = $leagueOptions->getLocations(); } if (Input::exists()) { if (Token::check(Input::get('token'))) { $validate = new Validation(); $validation = $validate->check($_POST, array('GroundName' => array('name' => 'Ground Name', 'min' => 5, 'max' => 50, 'required' => true), 'Town' => array('name' => 'Town', 'min' => 3, 'max' => 50), 'PostCode' => array('name' => 'Postcode', 'min' => 3, 'max' => 10))); if ($validation->passed()) { try { $leagueOptions->createLocation(array('GroundName' => Input::get('GroundName'), 'Town' => Input::get('Town'), 'PostCode' => Input::get('PostCode'))); Session::flash('locationCreation', 'Location created Successfully'); Redirect::to('locations.php'); } catch (Exception $e) { die($e->getMessage()); } $displayErrors = "none"; } else { $errorDisplay = ""; $displayErrors = "block"; foreach ($validation->errors() as $error) { $errorDisplay = $errorDisplay . $error . "<br>"; }