本文整理汇总了PHP中Validation::errors方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::errors方法的具体用法?PHP Validation::errors怎么用?PHP Validation::errors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create()
{
if ($post = $this->input->post()) {
$form = new Validation($post);
$form->add_rules('title', 'required');
$form->add_rules('introduction', 'required');
if ($form->validate()) {
$island = ORM::factory('island');
$island->user_id = Auth::instance()->get_user()->id;
$island->title = $post['title'];
$island->introduction = $post['introduction'];
$now = date('Y-m-d H:i:s');
$island->created = $now;
$island->modified = $now;
$island->save();
if ($island->saved) {
$this->session->set_flash('notice', 'Created new island!');
url::redirect('/sail/' . $island->code);
} else {
$this->session->set_flash('error', 'Failed to create new island!');
}
} else {
var_dump($form->errors());
die;
$this->session->set_flash('error', 'Error validating.');
}
}
}
示例2: _get_frm_valid
private function _get_frm_valid()
{
$form = array('txt_name' => '', 'txt_phone' => '', 'txt_fax' => '', 'txt_email' => '', 'txt_address' => '', 'txt_city' => '', 'txt_zipcode' => '', 'txt_contact' => '', 'txt_state' => '', 'txt_slogan' => '', 'txt_title' => '', 'txt_keyword' => '', 'txt_description' => '', 'txt_per_test' => '', 'txt_width' => '', 'txt_height' => '', 'rdo_enable_cart' => '', 'attach_logo' => '');
$errors = $form;
if ($_POST) {
$post = new Validation(array_merge($_POST, $_FILES));
if (!empty($_FILES['attach_logo']['name'])) {
$post->add_rules('attach_logo', 'upload::type[gif,jpg,png,jpeg]', 'upload::size[2M]');
}
$post->pre_filter('trim', TRUE);
$post->add_rules('txt_name', 'required');
$post->add_rules('txt_phone', 'required');
//$post->add_rules('txt_fax','phone[7,10,11,14]');
$post->add_rules('txt_email', 'required', 'email');
$post->pre_filter('trim', TRUE);
$post->add_rules('txt_width', 'digit');
$post->add_rules('txt_height', 'digit');
$post->add_rules('txt_per_test', 'digit');
if ($post->validate()) {
$form = arr::overwrite($form, $post->as_array());
return $form;
} else {
$errors = arr::overwrite($errors, $post->errors('site_validation'));
$str_error = '';
foreach ($errors as $id => $name) {
if ($name) {
$str_error .= $name . '<br>';
}
}
$this->session->set_flash('error_msg', $str_error);
}
}
url::redirect('admin_config');
die;
}
示例3: login
public function login()
{
$form = $errors = array("user" => "", "password" => "");
$post = new Validation($_POST);
$post->add_rules("user", "required");
$post->add_rules("password", "required");
if ($valid = $post->validate()) {
try {
$token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
Session::instance()->set("g3_client_access_token", $token);
$response = G3Remote::instance()->get_resource("gallery");
$valid = true;
$content = $this->_get_main_view($response->resource);
} catch (Exception $e) {
Kohana_Log::add("error", Kohana_Exception::text($e));
$valid = false;
}
}
if (!$valid) {
$content = new View('login.html');
$content->form = arr::overwrite($form, $post->as_array());
$content->errors = arr::overwrite($errors, $post->errors());
}
$this->auto_render = false;
print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string) $content));
}
示例4: edit
public function edit()
{
if (isset($_POST['save'])) {
$post = new Validation(array_merge($_POST, $_FILES));
//******** TO DO: trim for shipping info **************/
$post->pre_filter('trim', 'msg_text1', 'designpath', 'img_approved');
$post->add_rules('msg_text1', 'required');
$post->add_rules('designpath', 'required', 'numeric');
$post->add_rules('img_approved', 'numeric');
if (!$post->validate()) {
$errors = $post->errors('form_errors');
foreach ($errors as $error) {
echo '<p class="error">' . $error . '</p>';
}
} else {
$id = $this->uri->segment(3);
$basket = ORM::factory('orders_basket')->find($id);
$basket->msg_text1 = $post->msg_text1;
$basket->designpath = $post->designpath;
$basket->img_approved = $post->img_approved;
$basket->save();
/*************** TO DO: delete more than one category ****************/
}
}
$this->_renderView();
}
示例5: _get_record
private function _get_record()
{
$form = array('txt_name' => '', 'txt_email' => '', 'txt_phone' => '', 'txt_subject' => '', 'txt_content' => '', 'txt_code' => '', 'txt_last_name' => '', 'txt_first_name' => '', 'txt_company' => '');
$errors = $form;
if ($_POST) {
$post = new Validation($_POST);
$post->pre_filter('trim', TRUE);
$post->add_rules('txt_name', 'required');
$post->add_rules('txt_email', 'required', 'email');
$post->add_rules('txt_subject', 'required');
$post->add_rules('txt_content', 'required');
//$post->add_rules('txt_code','required');
//$post->add_callbacks('txt_random',array($this,'_check_security_code'));
//$post->add_rules('sel_send','trim');
if ($post->validate()) {
$form = arr::overwrite($form, $post->as_array());
return $form;
} else {
$form = arr::overwrite($form, $post->as_array());
// Retrieve input data
$this->session->set_flash('input_data', $form);
// Set input data in session
$errors = arr::overwrite($errors, $post->errors('contact_validation'));
$error_msg = '';
foreach ($errors as $id => $name) {
if ($name) {
$error_msg .= '<br>' . $name;
}
}
$this->session->set_flash('error_msg', $error_msg);
url::redirect('contact');
die;
}
}
}
示例6: _get_record_aut_config
private function _get_record_aut_config()
{
$form = array('txt_aut_api_login' => '', 'txt_aut_transaction_key' => '', 'sel_aut_post_url' => '');
$errors = $form;
if ($_POST) {
$post = new Validation($_POST);
$post->pre_filter('trim', TRUE);
$post->add_rules('txt_aut_api_login', 'trim', 'required');
$post->add_rules('txt_aut_transaction_key', 'trim', 'required');
$post->add_rules('sel_aut_post_url', 'trim', 'required');
$form = arr::overwrite($form, $post->as_array());
$form = $this->_set_form_aut_config($form);
if ($post->validate()) {
return $form;
} else {
$this->session->set_flash('frm_aut', $form);
$errors = arr::overwrite($errors, $post->errors('authorizenet_config_validation'));
$str_error = '';
foreach ($errors as $id => $name) {
if ($name) {
$str_error .= '<br>' . $name;
}
}
$this->session->set_flash('error_msg', $str_error);
url::redirect('admin_payment_method');
die;
}
}
}
示例7: create
public function create()
{
$this->template->content = new View('users/create');
$form = new Validation($_POST);
$form->pre_filter('trim', true);
$form->add_rules('username', 'required')->add_rules('password', 'required')->add_rules('email', 'required', 'valid::email');
$this->template->content->repopulate = $form;
if ($form->validate()) {
// Create new user
$user = new User_Model();
if (!$user->username_exists($this->input->post('username'))) {
foreach ($form->as_array() as $key => $val) {
// Set user data
$user->{$key} = $val;
}
if ($user->validate($form->as_array())) {
if ($user->add(ORM::factory('role', 'login')) and $user->save()) {
// Redirect to the login page
url::redirect('login');
}
}
}
}
// Error
$this->template->content->error = $form->errors('login');
}
示例8: pricing
private function pricing()
{
$this->shell->meta = 'Plans and pricing for testimonial and review layouts and templates for your website';
$this->shell->content = new View('marketing/testimonials/start');
$this->shell->title = 'Plans and Pricing';
if (empty($_POST)) {
die($this->shell);
}
# handle the POST.
$this->shell->content->values = $_POST;
$post = new Validation($_POST);
$post->pre_filter('trim');
$post->add_rules('email', 'required', 'valid::email');
$post->add_rules('password', 'required', 'matches[password2]', 'valid::alpha_dash');
if (!$post->validate()) {
$this->shell->content->errors = $post->errors();
die($this->shell);
}
$new_owner = ORM::factory('owner');
# unique email.
if (!$new_owner->email_available($_POST['email'])) {
$this->shell->content->errors = 'Email Already Exists!';
die($this->shell);
}
$new_owner->email = $_POST['email'];
$new_owner->password = $_POST['password'];
$new_owner->save();
# log the user in and take to admin
$this->auth->force_login($new_owner);
url::redirect('/admin/login');
}
示例9: handler
public function handler()
{
access::verify_csrf();
$form = $this->_get_form();
$errors = array_fill_keys(array_keys($form), "");
if ($_POST) {
$post = new Validation($_POST);
$post->add_rules("updates_enabled", array("valid", "numeric"));
$post->add_rules("popular_enabled", array("valid", "numeric"));
$post->add_rules("updates_limit", array("valid", "numeric"));
$post->add_rules("popular_limit", array("valid", "numeric"));
$post->add_rules("updates_description", "length[0,2048]");
$post->add_rules("popular_description", "length[0,2048]");
if ($post->validate()) {
foreach (array("updates", "popular") as $album) {
$album_defn = unserialize(module::get_var("dynamic", $album));
$album_defn->enabled = $post["{$album}_enabled"];
$album_defn->description = $post["{$album}_description"];
$album_defn->limit = $post["{$album}_limit"] === "" ? null : $post["{$album}_limit"];
module::set_var("dynamic", $album, serialize($album_defn));
}
message::success(t("Dynamic Albums Configured"));
url::redirect("admin/dynamic");
} else {
$form = arr::overwrite($form, $post->as_array());
$errors = arr::overwrite($errors, $post->errors());
}
}
print $this->_get_view($form, $errors);
}
示例10: add
public function add()
{
$argumentarray = Router::$arguments;
//$id = $argumentarray[0];
if (isset($_POST['save'])) {
$post = new Validation(array_merge($_POST, $_FILES));
$post->pre_filter('trim', 'foilName', 'foilHexcode');
$post->add_rules('foilName', 'required');
$post->add_rules('foilHexcode', 'required');
if (!$post->validate()) {
$errors = $post->errors('form_errors');
foreach ($errors as $error) {
echo '<p class="error">' . $error . '</p>';
}
} else {
//$id = $argumentarray[0];
$foils = new Foil_Color_Model();
$foil = ORM::factory('foil_color');
$foil->name = $post->foilName;
$foil->hexcode = $post->foilHexcode;
try {
$foil->save();
$foils = new Foil_Color_Model();
$id = $foils->getNextID();
url::redirect('/foils/edit/' . $foil->id);
} catch (Exception $ex) {
echo 'There was an error adding this foil: ' . $ex->getMessage();
//url::redirect('/foils/');
}
}
}
$this->_renderView();
}
示例11: post_review
private function post_review($page_name, $review_id)
{
# validate the form values.
$post = new Validation($_POST);
$post->pre_filter('trim');
$post->add_rules('body', 'required');
$post->add_rules('name', 'required');
$post->add_rules('email', 'required');
# on error
if (!$post->validate()) {
$view = new View('public_review/reviews/add_form');
$view->page_name = $page_name;
$view->errors = $post->errors();
$view->values = $_POST;
return $view;
}
# on success
$new_item = ORM::factory('review_item');
$new_item->review_id = $review_id;
$new_item->fk_site = $this->site_id;
$new_item->body = $_POST['body'];
$new_item->rating = $_POST['rating'];
$new_item->name = $_POST['name'];
$new_item->save();
$view = new View('public_review/reviews/status');
$view->success = true;
return $view;
}
示例12: _get_frm_valid
private function _get_frm_valid()
{
$hd_id = $this->input->post('hd_id');
$form = $this->data_template_model->get_frm();
$errors = $form;
if ($_POST) {
$post = new Validation($_POST);
$post->pre_filter('trim', TRUE);
$post->add_rules('txt_name', 'required', 'length[1,200]');
$post->add_rules('txt_content', 'required');
if ($post->validate()) {
$form = arr::overwrite($form, $post->as_array());
return $form;
} else {
$form = arr::overwrite($form, $post->as_array());
$errors = arr::overwrite($errors, $post->errors('account_validation'));
$str_error = '';
foreach ($errors as $id => $name) {
if ($name) {
$str_error .= $name . '<br>';
}
}
$this->session->set_flash('error_msg', $str_error);
if ($hd_id) {
url::redirect('admin_emailtemplate/edit/' . $hd_id);
}
die;
}
}
}
示例13: action_show
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);
}
示例14: action_edit_field
public function action_edit_field()
{
$field_id = $this->request->param('options');
xml::to_XML(array('field' => array('@id' => $field_id, '$content' => User::get_data_field_name($field_id))), $this->xml_content);
if (count($_POST) && isset($_POST['field_name'])) {
$post = new Validation($_POST);
$post->filter('trim');
$post->rule('Valid::not_empty', 'field_name');
if ($post->validate()) {
$post_values = $post->as_array();
if ($post_values['field_name'] != User::get_data_field_name($field_id) && !User::field_name_available($post_values['field_name'])) {
$post->add_error('field_name', 'User::field_name_available');
}
}
// Retry
if ($post->validate()) {
$post_values = $post->as_array();
User::update_field($field_id, $post_values['field_name']);
$this->add_message('Field ' . $post_values['field_name'] . ' updated');
$this->set_formdata(array('field_name' => $post_values['field_name']));
} else {
$this->add_error('Fix errors and try again');
$this->add_form_errors($post->errors());
$this->set_formdata(array_intersect_key($post->as_array(), $_POST));
}
} else {
$this->set_formdata(array('field_name' => User::get_data_field_name($field_id)));
}
}
示例15: add
public function add()
{
if (isset($_POST['save'])) {
$post = new Validation(array_merge($_POST, $_FILES));
$post->pre_filter('trim', 'typeName', 'typeDescription', 'typeShortDescription', 'metaTitle', 'metaDescription', 'metaKeywords');
$post->add_rules('typeName', 'required');
if (!$post->validate()) {
$errors = $post->errors('form_errors');
foreach ($errors as $error) {
echo '<p class="error">' . $error . '</p>';
}
} else {
$id = $this->uri->segment(3);
$type = ORM::factory('products_type')->find($id);
$type->name = $post->typeName;
$type->category_id = $post->category;
$type_desc = ORM::factory('products_types_description')->where('id', $type->products_types_description_id)->find();
$type_desc->short_description = $post->typeShortDescription;
$type_desc->description = $post->typeDescription;
$type_desc->meta_title = $post->metaTitle;
$type_desc->meta_description = $post->metaDescription;
$type_desc->meta_keywords = $post->metaKeywords;
$type_desc->title_url = $post->metaUrl;
$type_desc->image_alt = $post->image_alt;
$type_desc->video = $post->video;
if (!empty($_FILES['image']['name'])) {
// uses Kohana upload helper
$_FILES = Validation::factory($_FILES)->add_rules('image', 'upload::valid', 'upload::type[gif,jpg,jpeg,png]', 'upload::size[2M]');
if ($_FILES->validate()) {
// Temporary file name
$filename = upload::save('image', basename($_FILES['image']['tmp_name']));
$file = basename($_FILES['image']['name']);
// Resize, sharpen, and save the image
Image::factory($filename)->save(DOCROOT . '../../env/product_type_images/' . $file);
// Remove the temporary file
unlink($filename);
$type_desc->image = $file;
$type_desc->save();
} else {
$errors = $_FILES->errors('form_user');
}
}
$type_desc->save();
$type->products_types_description_id = $type_desc->id;
$type->save();
if (!empty($post->productTypeSites)) {
foreach ($post->productTypeSites as $site_id) {
$sc = ORM::factory('sites_types')->where('products_type_id', $type->id)->where('site_id', $site_id)->find();
if ($sc->id == 0) {
$sc->products_type_id = $type->id;
$sc->site_id = $site_id;
$sc->save();
}
}
}
url::redirect(url::base() . $this->uri->segment(1) . '/' . $this->uri->segment(2) . '/' . $type->id);
}
}
$this->_renderView();
}