当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::add_rules方法代码示例

本文整理汇总了PHP中Validation::add_rules方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::add_rules方法的具体用法?PHP Validation::add_rules怎么用?PHP Validation::add_rules使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validation的用法示例。


在下文中一共展示了Validation::add_rules方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 public function validate(Validation $array, $save = FALSE)
 {
     $array->pre_filter('trim');
     $array->add_rules('taxon_group_id', 'required');
     $array->add_rules('taxon_list_id', 'required');
     return parent::validate($array, $save);
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:7,代码来源:taxon_groups_taxon_list.php

示例2: _get_register_valid

 private function _get_register_valid()
 {
     $form = array('txt_email' => '', 'txt_password' => '', 'txt_cfpass' => '', 'txt_email' => '', 'txt_random' => '', 'txt_fname' => '', 'txt_lname' => '', 'txt_cpname' => '', 'txt_spname' => '', 'txt_spemail' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('txt_password', 'required', 'length[1,50]');
         $post->add_rules('txt_cfpass', 'required', 'matches[txt_password]');
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_rules('txt_random', 'required');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         //$post->add_callbacks('txt_random',array($this,'_check_security_code'));
         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('register_validation'));
             $str_error = '';
             foreach ($errors as $id => $name) {
                 if ($name) {
                     $str_error .= $name . '<br>';
                 }
             }
             $this->session->set_flash('error_msg', $str_error);
             url::redirect('register');
             die;
         }
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:34,代码来源:register_bk.php

示例3: add

 public function add()
 {
     $form = array('building_id' => '', 'name' => '', 'index' => '', 'img_uri' => '', 'active' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', true);
         $post->add_rules('buildings_id', 'required', 'digit');
         $post->add_rules('name', 'required');
         $post->add_rules('index', 'required');
         $post->add_rules('img_uri', 'required');
         $post->add_rules('active', 'required');
         if ($post->validate()) {
             // check for invilid
             $form = arr::overwrite($form, $post->as_array());
             $people = new Person_Model();
             $result = $people->save($this->input->get('person'), $person_id);
         } else {
             $form = arr::overwrite($form, $post->as_array());
             client::validation_results(arr::overwrite($errors, $post->errors('hiring_employee_form_validations')));
             client::messageSend("There were errors in some fields", E_USER_WARNING);
         }
     }
     $building = new Building_Model();
     $buildings_list = $building->select_list();
     $this->template->title = 'Seating::Spaces::Add';
     $this->template->content = new View('pages/spaces_add');
     $this->template->content->form = $form;
     $this->template->content->buildings_list = $buildings_list;
 }
开发者ID:samkeen,项目名称:Confab-Server,代码行数:30,代码来源:spaces.php

示例4: 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.');
         }
     }
 }
开发者ID:jmhobbs,项目名称:q-aargh,代码行数:28,代码来源:island.php

示例5: validate

 public function validate(Validation $array, $save = FALSE)
 {
     // uses PHP trim() to remove whitespace from beginning and end of all fields before validation
     $array->pre_filter('trim');
     // merge unvalidated fields, in case the subclass has set any.
     if (!isset($this->unvalidatedFields)) {
         $this->unvalidatedFields = array();
     }
     $this->unvalidatedFields = array_merge($this->unvalidatedFields, array('validation_rules', 'public', 'multi_value', 'deleted'));
     $array->add_rules('caption', 'required');
     $array->add_rules('data_type', 'required');
     if (array_key_exists('data_type', $array->as_array()) && $array['data_type'] == 'L') {
         if (empty($array['termlist_id'])) {
             $array->add_rules('termlist_id', 'required');
         } else {
             array_push($this->unvalidatedFields, 'termlist_id');
         }
     }
     $array->add_rules('system_function', 'length[1,30]');
     $parent_valid = parent::validate($array, $save);
     // clean up cached required fields in case validation rules have changed
     $cache = Cache::instance();
     $cache->delete_tag('required-fields');
     if ($save && $parent_valid) {
         // clear the cache used for attribute datatype and validation rules since the attribute has changed
         $cache = new Cache();
         // Type is the object name with _attribute stripped from the end
         $type = substr($this->object_name, 0, strlen($this->object_name) - 10);
         $cache->delete('attrInfo_' . $type . '_' . $this->id);
     }
     return $save && $parent_valid;
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:32,代码来源:ATTR_ORM.php

示例6: 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;
 }
开发者ID:plusjade,项目名称:plusjade,代码行数:28,代码来源:review.php

示例7: validation_settings

 public function validation_settings(Validation $v)
 {
     // Rules
     $v->add_rules('good_id', 'required', 'numeric', 'length[30]', array($v, 'unique_ids'));
     $v->add_rules('bad_id', 'required', 'numeric', 'length[30]', array($v, 'unique_ids'));
     // Errors
 }
开发者ID:jrschumacher,项目名称:oets,代码行数:7,代码来源:Ticket_Bannerdupes_Model.php

示例8: 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();
 }
开发者ID:VinceOmega,项目名称:mcb-nov-build,代码行数:33,代码来源:foils.php

示例9: 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));
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:26,代码来源:g3_client.php

示例10: activate

 public function activate()
 {
     access::verify_csrf();
     $post = new Validation($_POST);
     $post->add_rules("activate_users", "required");
     $post->add_rules("activate", "alpha_numeric");
     if ($post->validate()) {
         $names = array();
         if (!empty($post->activate)) {
             foreach ($post->activate as $id) {
                 $user = register::create_new_user($id);
                 $names[] = $user->name;
             }
             message::success(t("Activated %users.", array("users" => implode(", ", $names))));
         }
         $count = ORM::factory("pending_user")->where("state", "!=", 2)->count_all();
         if ($count == 0) {
             site_status::clear("pending_user_registrations");
         }
         url::redirect("admin/register");
     }
     list($form, $errors) = $this->_get_form();
     $form = array_merge($form, $post->as_array());
     $errors = array_merge($errors, $post->errors());
     print $this->_get_admin_view($form, $errors);
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:26,代码来源:admin_register.php

示例11: form_handler

 private function form_handler($page_name, $newsletter)
 {
     $view = new View('public_newsletter/newsletters/form');
     $view->page_name = $page_name;
     $values = array('name' => '', 'email' => '');
     $view->values = $values;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim');
         $post->add_rules('name', 'required');
         $post->add_rules('email', 'required', 'valid::email');
         if (!$post->validate()) {
             $view->errors = arr::overwrite($values, $post->errors('form_error_messages'));
             $view->values = arr::overwrite($values, $post->as_array());
             return $view;
         }
         include Kohana::find_file('vendor', 'CMBase');
         $cm = new CampaignMonitor(null, null, $newsletter->cm_list_id);
         $result = $cm->subscriberAdd($_POST['email'], $_POST['name']);
         if ($result['Result']['Code'] != 0) {
             kohana::log('error', $result['Result']['Message']);
             return 'There was an error adding you to the emailing list. Please try again later.';
         }
         return 'Thank you! You have been adding to our mailing list.';
     }
     return $view;
 }
开发者ID:plusjade,项目名称:plusjade,代码行数:27,代码来源:newsletter.php

示例12: 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();
 }
开发者ID:VinceOmega,项目名称:mcb-nov-build,代码行数:26,代码来源:orders_baskets.php

示例13: upload

 public function upload()
 {
     access::verify_csrf();
     $validation = new Validation(array_merge($_POST, $_FILES));
     $validation->add_rules("zip_file", "upload::valid", "upload::required", "upload::type[zip]");
     $validation->add_rules("is_admin", "chars[0,1]");
     $validation->add_callbacks("zip_file", array($this, "_unload_zip"));
     if ($validation->validate()) {
         $session = Session::instance();
         $themeroller_name = $session->get("themeroller_name");
         $is_admin = $validation["is_admin"];
         $counter = 0;
         $theme_name_generated = $theme_name = ($is_admin ? "admin_" : "") . $themeroller_name;
         while (file_exists(THEMEPATH . "{$theme_name_generated}/theme.info")) {
             $counter++;
             $theme_name_generated = "{$theme_name}_{$counter}";
         }
         $theme_name = strtolower(strtr($theme_name_generated, " ", "_"));
         $session->set("theme_name", $theme_name);
         $session->set("themeroller_is_admin", $is_admin);
         print "FILEID: {$validation["zip_file"]["tmp_name"]}";
     } else {
         header("HTTP/1.1 400 Bad Request");
         print "ERROR: " . t("Invalid zip archive");
     }
 }
开发者ID:webmatter,项目名称:gallery3-contrib,代码行数:26,代码来源:admin_themeroller.php

示例14: _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;
         }
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:30,代码来源:admin_emailtemplate.php

示例15: test_data_create

 public function test_data_create()
 {
     access::verify_csrf();
     list($form, $errors) = $this->_get_test_data_form();
     $post = new Validation($_POST);
     $post->add_rules("albums", "numeric");
     $post->add_rules("photos", "numeric");
     $post->add_rules("comments", "numeric");
     $post->add_rules("tags", "numeric");
     $post->add_callbacks("albums", array($this, "_set_default"));
     $post->add_callbacks("photos", array($this, "_set_default"));
     $post->add_callbacks("comments", array($this, "_set_default"));
     $post->add_callbacks("tags", array($this, "_set_default"));
     if ($post->validate()) {
         $task_def = Task_Definition::factory()->callback("developer_task::create_content")->description(t("Create test content"))->name(t("Create Test Data"));
         $total = $post->albums + $post->photos + $post->comments + $post->tags;
         $success_msg = t("Successfully generated test data");
         $error_msg = t("Problems with test data generation was encountered");
         $task = task::create($task_def, array("total" => $total, "batch" => (int) ceil($total / 10), "success_msg" => $success_msg, "current" => 0, "error_msg" => $error_msg, "albums" => $post->albums, "photos" => $post->photos, "comments" => $post->comments, "tags" => $post->tags));
         batch::start();
         print json_encode(array("result" => "started", "max_iterations" => $total + 5, "url" => url::site("admin/developer/run_task/{$task->id}?csrf=" . access::csrf_token()), "task" => $task->as_array()));
     } else {
         $v = $this->_get_test_data_view(arr::overwrite($form, $post->as_array()), arr::overwrite($errors, $post->errors()));
         print json_encode(array("result" => "error", "form" => $v->__toString()));
     }
 }
开发者ID:ChrisRut,项目名称:gallery3-contrib,代码行数:26,代码来源:admin_developer.php


注:本文中的Validation::add_rules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。