本文整理汇总了PHP中Validate::errors方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::errors方法的具体用法?PHP Validate::errors怎么用?PHP Validate::errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _upload_image
public function _upload_image(Validate $array, $input)
{
if ($array->errors()) {
// Don't bother uploading
return;
}
// Get the image from the array
$image = $array[$input];
if (!Upload::valid($image) or !Upload::not_empty($image)) {
// No need to do anything right now
return;
}
if (Upload::valid($image) and Upload::type($image, $this->types)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
if ($file = Upload::save($image, NULL, $this->directory)) {
Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
// Update the image filename
$array[$input] = $filename;
// Delete the temporary file
unlink($file);
} else {
$array->error('image', 'failed');
}
} else {
$array->error('image', 'valid');
}
}
示例2: validate_latlong_required_as_pair
public function validate_latlong_required_as_pair(Validate $validate, $field)
{
// if we are already invalid, just return
if (array_key_exists($field, $validate->errors())) {
return;
}
$other_field = $field == 'lat' ? 'long' : 'lat';
if (!empty($validate[$field]) && empty($validate[$other_field])) {
$validate->error($other_field, 'required_if_other_given', array($field));
}
}
示例3: set
public function set($data)
{
foreach ($data as $key => $value) {
$this->_fields[$key] = $value;
}
if (isset($this->schema)) {
$validate = new Validate();
$validate->check($this->_fields, $this->schema, $this->_identifier);
if (!$validate->passed()) {
$this->_errors = $validate->errors();
}
}
$this->clean();
}
示例4: dispatch
public static function dispatch($class)
{
if (!class_exists($class)) {
include_once 'controllers/' . str_replace('_', '/', $class) . '.php';
}
$instance = new $class();
$params = array_slice(func_get_args(), 1);
$return = true;
if (method_exists($instance, 'init')) {
$return = call_user_func_array(array($instance, 'init'), $params);
}
if (!(true === $return)) {
if (is_string($return) || $return instanceof Url) {
Url::redirect($return);
}
return false;
}
$errors = array();
if (Request::isPost()) {
$validation = new Validate();
if ($rules = $instance->validation()) {
$validation->add($rules);
$validation->validate();
}
if ($validation->valid()) {
$return = $instance->post();
if (!(false === $return)) {
if (is_string($return) || $return instanceof Url) {
Url::redirect($return);
}
return true;
}
}
$errors = $validation->errors();
}
$return = $instance->get();
if (!(false === $return)) {
$return['errors'] = $errors;
$view = new View($class, $return);
$viewContent = $view->dispatch();
return $viewContent;
}
return false;
}
示例5: changePassword
function changePassword()
{
$input = Input::parse();
if (Token::check($input['token'])) {
$validate = new Validate();
$validate->check($input, array('password_current' => ['required' => true, 'min' => 6], 'password' => ['required' => true, 'min' => 6], 'password_repeat' => ['required' => true, 'min' => 6, 'matches' => 'password']));
if ($validate->passed()) {
$user = new User();
if (Hash::make($input['password_current'], config::get('encryption/salt')) !== $user->data()->password) {
echo "incorrent password";
} else {
$user->update(array('password' => Hash::make($input['password'], config::get('ecryption/salt'))));
Session::flash('success', 'Successfully changed password');
Redirect::to('changepassword');
}
} else {
Session::flash('error', $validate->errors());
Redirect::to('changepassword');
}
}
}
示例6: action_upload
/**
* Processes an uploaded image
*
* @return null
*/
public function action_upload()
{
// Validate the upload first
$validate = new Validate($_FILES);
$validate->rules('image', array('Upload::not_empty' => null, 'Upload::valid' => null, 'Upload::size' => array('4M'), 'Upload::type' => array(array('jpg', 'png', 'gif'))));
if ($validate->check(true)) {
// Shrink the image to the lowest max dimension
$image = Image::factory($_FILES['image']['tmp_name']);
$constraints = Kohana::config('image')->constraints;
$image->resize($constraints['max_width'], $constraints['max_height']);
$image->save(APPPATH . 'photos/' . $_FILES['image']['name']);
$photo = new Model_Vendo_Photo();
$photo->file = APPPATH . 'photos/' . $_FILES['image']['name'];
$photo->save();
unlink(APPPATH . 'photos/' . $_FILES['image']['name']);
$this->request->redirect('admin/photo');
} else {
Session::instance()->set('errors', $validate->errors('validate'));
$this->request->redirect('admin/photo');
}
}
示例7: signup
function signup()
{
$input = Input::parse();
if (Token::check($input['token'])) {
$validate = new Validate();
$validate->check($input, array('username' => ['required' => true, 'min' => 5, 'max' => 20, 'unique' => 'users'], 'name' => ['required' => true, 'max' => 50], 'password' => ['required' => true, 'min' => 6]));
if ($validate->passed()) {
$user = new User();
$salt = config::get("encription/hash");
try {
$user->create(array('username' => $input['username'], 'password' => Hash::make($input['password']), 'name' => $input['name'], 'joined' => date('Y-m-d H:i:s'), 'group_id' => 1));
} catch (Exception $e) {
die($e->getMessage());
}
Session::flash('login', 'You registered successfully! Please login!');
Redirect::to('login');
} else {
Session::flash('error', $validate->errors());
Redirect::to('signup');
}
} else {
echo "Invalid token";
}
}
示例8: action_recover_request
public function action_recover_request()
{
$view = View::factory('login/recover');
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$post = new Validate($_POST);
$post->rules('email', array('not_empty' => array(), 'email' => array()));
if ($post->check()) {
$user = ORM::factory('user')->where('email', '=', $post['email'])->find();
if ('True' == $user->email_verified) {
$user->generate_key();
$user->save();
/*
//send an email
$q = new Pheanstalk_Model('codewars-email');
$q->put('password:'.$user->id,Pheanstalk_Model::PRIORITY_HIGH);
*/
$html_email = View::factory('login/recover_email_html');
$text_email = View::factory('login/recover_email_text');
$link = url::site('login/recover/?' . 'key=' . $user->activation_key . '&id=' . $user->id);
View::bind_global('link', $link);
$email = new Model_Email();
$messages = $email->message(array($user->email => $user->fullname()), '[Code-Wars] Password Recovery', $html_email, $text_email);
if (false === $messages) {
$view->set('message', 'Looks like email has not been configured serverside');
} else {
$view = View::factory('login/recover_sent');
}
} else {
$view->set('message', 'Your email address was not verified we can not send you a password recovery email');
}
} else {
$view->set('message', $post->errors('login_errors'));
}
}
$this->request->response = $view;
}
示例9: unset
echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
echo 'Please verify you\'re not a robot';
echo '</div>';
break;
default:
echo '<div class="alert alert-danger alert-dismissible" role="alert">';
echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
echo $errors;
echo '</div>';
break;
}
}
unset($validate);
}
if (isset($otp_validate)) {
foreach ($otp_validate->errors() as $errors) {
echo '<div class="alert alert-warning alert-dismissible" role="alert">';
echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
echo $errors;
echo '</div>';
}
unset($otp_validate);
}
if (Session::exists('OTP Sending') && Session::get('OTP Sending') != 'Incorrect, Enter Again' && Session::get('OTP Sending') != '') {
echo '<div class="alert alert-success alert-dismissible" role="alert">';
echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>';
echo Session::get('OTP Sending');
echo '</div>';
}
if (Session::exists('OTP Sending') && Session::get('OTP Sending') == 'Incorrect, Enter Again') {
echo '<div class="alert alert-danger alert-dismissible" role="alert">';
示例10: test_check
/**
* Tests Validate::check()
*
* @test
* @covers Validate::check
* @covers Validate::callbacks
* @covers Validate::callback
* @covers Validate::rule
* @covers Validate::rules
* @covers Validate::errors
* @covers Validate::error
* @dataProvider provider_check
* @param string $url The url to test
* @param boolean $expected Is it valid?
*/
public function test_check($array, $rules, $callbacks, $expected, $expected_errors)
{
$validate = new Validate($array);
foreach ($rules as $field => $rule)
{
$validate->rule($field, $rule[0], array($rule[1]));
}
foreach ($callbacks as $field => $callback)
$validate->callback($field, $callback);
$status = $validate->check();
$errors = $validate->errors(TRUE);
$this->assertSame($expected, $status);
$this->assertSame($expected_errors, $errors);
$validate = new Validate($array);
foreach ($rules as $field => $rule)
$validate->rules($field, array($rule[0] => array($rule[1])));
$this->assertSame($expected, $validate->check());
}
示例11: setErrors
public static function setErrors($errors)
{
self::$errors = $errors;
}
示例12: action_log
public function action_log($project_id = 0)
{
// Get project data
$project_data = $this->model_gather->get_project_data($project_id);
// Verify that project exists
if (count($project_data) == 0) {
echo "<p>Project with this ID does not exist.</p>";
} else {
$project_data = array_pop($project_data);
$view = View::factory('template');
$view->page_title = $project_data['project_title'] . " - Gather Log";
$view->page_content = View::factory('pages/gather_log');
// Default results display
$result_params = array('date_from' => 0, 'date_to' => 0, 'num_results' => 100, 'order' => 'desc');
$form_errors = "";
if ($_POST) {
// Form validation
$post = new Validate($_POST);
$post->rule('datef_m', 'digit')->rule('datef_d', 'digit')->rule('datef_y', 'digit')->rule('datet_m', 'digit')->rule('datet_d', 'digit')->rule('datet_y', 'digit');
$field_data = $post->as_array();
// For form re-population
if ($post->check()) {
// Process results display parameters
if ($field_data['datef_m'] > 0 and $field_data['datef_y'] > 0 and $field_data['datef_y'] > 0) {
$result_params['date_from'] = mktime(0, 0, 0, $field_data['datef_m'], $field_data['datef_d'], $field_data['datef_y']);
}
if ($field_data['datet_m'] > 0 and $field_data['datet_y'] > 0 and $field_data['datet_y'] > 0) {
$result_params['date_to'] = mktime(0, 0, 0, $field_data['datet_m'], $field_data['datet_d'], $field_data['datet_y']);
}
$result_params['num_results'] = $field_data['num_results'];
$result_params['order'] = strtoupper($field_data['order']);
} else {
$form_errors = $post->errors('results');
}
} else {
// Populate form w/ empty values
$field_data = array('datef_m' => '', 'datef_d' => '', 'datef_y' => '', 'datet_m' => '', 'datet_d' => '', 'datet_y' => '', 'num_results' => $result_params['num_results'], 'order' => $result_params['order']);
}
$results = $this->model_gather->get_gather_log($project_id, $result_params);
$view->page_content->field_data = $field_data;
$view->page_content->results = $results;
$view->page_content->errors = $form_errors;
$this->request->response = $view;
}
}
示例13: validate
public function validate($source, $rules = [])
{
$this->errors = null;
$validate = new Validate();
if (!empty($rules)) {
if ($validate->check($source, $rules)->passed()) {
return true;
} else {
$this->errors = $validate->errors();
return false;
}
} else {
if (!empty($this->validate)) {
if ($validate->check($source, $this->validate)->passed()) {
return true;
} else {
$this->errors = $validate->errors();
return false;
}
} else {
return true;
}
}
return false;
}
示例14: post
public function post($post_id)
{
$this->model('User');
$this->model('Article');
$user = new User();
$article = new Article();
$this->loginRequired($user);
// If new post is to be created
if (empty($post_id) || $post_id == 'new') {
if (Input::exists()) {
$validate = new Validate();
// Validation for Inputs
$validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true), 'link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE)));
if (empty(Input::get('type'))) {
$type = 0;
} else {
$type = 1;
}
if ($validate->passed()) {
$template = Strings::get('catagory');
try {
$article->create(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CREATED_DATE' => date("Y-m-d H:i:s", time()), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template')));
// Get the created article details from LINK to redirect the user to edit it.
$newarticle = new Article(Input::get('link'));
Redirect::to(ADMINPATH . 'post/' . $newarticle->data()->SL_NO);
} catch (Exception $e) {
die($e->getMessage());
}
if (isset($data)) {
$submissionData = Input::values($_POST);
$data = array_merge($data, $submissionData);
} else {
$data = Input::values($_POST);
}
} else {
$data = $validate->errors();
}
}
if (isset($data)) {
$submissionData = Input::values($_POST);
$data = array_merge($data, $submissionData);
} else {
$data = Input::values($_POST);
}
$data['CATAGORY'] = Strings::get('catagory');
$data['SUBCATAGORY'] = Strings::get('subcatagory');
$data['TEMPLATES'] = Strings::get('templates');
$data['token'] = Token::generate();
$data['TITLE'] = "Create New Post";
$this->view('admin/post.new.html', $data);
} else {
/**
* Edit Post section
*
* The edit and after creation events happen here
*/
$article = new Article($post_id);
if (Input::exists()) {
$validate = new Validate();
// Validation for Inputs
$validation = $validate->check($_POST, array('title' => array('name' => 'Post title', 'required' => true, 'min' => 5), 'description' => array('name' => 'description', 'required' => true, 'min' => 50), 'featuredimage' => array('name' => 'Featured Image', 'required' => true)));
// If Article URL is changed check if it already exist
if ($validate->passed() && $article->data()->LINK != Input::get('link')) {
$validation = $validate->check($_POST, array('link' => array('name' => 'Article Link', 'required' => true, 'unique' => ARTICLE_TABLE)));
}
if (empty(Input::get('type'))) {
$type = 0;
} else {
$type = 1;
}
if (empty(Input::get('featured'))) {
$featured = 0;
} else {
$featured = 1;
}
if (Input::get('publish') == 1) {
$publish = $article->data()->STATUS ? 0 : 1;
} else {
$publish = $article->data()->STATUS;
}
if ($validation) {
$template = Strings::get('catagory');
try {
$article->update(array('TITLE' => Input::get('title'), 'SECURL' => Input::get('catagory'), 'SUBSEC' => Input::get('subsec'), 'CONTENT' => Input::get('content'), 'DATE' => Input::get('date'), 'IMG' => Input::get('featuredimage'), 'DES' => Input::get('description'), 'LINK' => Input::get('link'), 'TYPE' => $type, 'TEMPLATE' => Input::get('template'), 'FEATURED' => $featured, 'STATUS' => $publish), $post_id);
Redirect::to(ADMINPATH . 'post/' . $post_id);
} catch (Exception $e) {
die($e->getMessage());
}
if (isset($data)) {
$submissionData = Input::values($_POST);
$data = array_merge($data, $submissionData);
} else {
$data = Input::values($_POST);
}
} else {
$data = $validate->errors();
}
}
if ($article->count()) {
if (isset($data)) {
//.........这里部分代码省略.........
示例15: Validate
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
$validate = new Validate();
$validation = $validate->check($_POST, array('current_password' => array('required' => true, 'min' => 6), 'new_password' => array('required' => true, 'min' => 6), 'new_password_again' => array('required' => true, 'min' => 6, 'matches' => 'new_password')));
if ($validate->passed()) {
if (Hash::make(Input::get('current_password'), $user->data()->salt) !== $user->data()->password) {
Session::flash('error', 'Your current password is incorrect.');
Redirect::to('changepassword.php');
} else {
$salt = Hash::salt(32);
$user->update(array('password' => Hash::make(Input::get('new_password'), $salt), 'salt' => $salt));
Session::flash('success', 'Your password has been changed!');
Redirect::to('index.php');
}
} else {
foreach ($validate->errors() as $error) {
echo $error, '<br>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>OOP Login/Register</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
<link href="css/material.css" rel="stylesheet">
开发者ID:TalehFarzaliey,项目名称:PHP-OOP-User-System-with-Bootstrap-Material-Design,代码行数:31,代码来源:changepassword.php