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


PHP Validation::validate方法代码示例

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


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

示例1: 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)));
     }
 }
开发者ID:rockymontana,项目名称:kohana-module-pajas,代码行数:29,代码来源:fields.php

示例2: validate

 function validate()
 {
     $post = new Validation($_POST);
     $post->add_rules('username', 'required');
     $post->add_rules('password', 'required');
     if (!$post->validate()) {
         echo '必须填写用户名和密码';
         return;
     }
     $username = $_POST['username'];
     $password = $_POST['password'];
     $user_orm = ORM::factory('user')->where(array('name' => $username, 'password' => sha1($password)))->find();
     if ($user_orm->loaded) {
         $id = $user_orm->id;
         if ($user_orm->active == 1) {
             $this->session->set('user_id', $id);
             $this->session->set('username', $username);
             $this->session->set('role_id', $user_orm->role_id);
             respOk(array());
         } else {
             $message = "登录失败,用户处于禁止状态";
             respFailed($message);
         }
     } else {
         $message = "登录失败,用户名或密码错误";
         respFailed($message);
     }
     return;
 }
开发者ID:easthero,项目名称:kohana,代码行数:29,代码来源:login.php

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

示例4: reset

 public function reset()
 {
     if ($this->owner->logged_in()) {
         url::redirect('/admin/testimonials/display');
     }
     $login_shell = new View('admin/login_shell');
     $login_shell->content = new View('admin/reset');
     if (empty($_POST)) {
         die($login_shell);
     }
     $post = new Validation($_POST);
     $post->pre_filter('trim');
     $post->add_rules('email', 'required', 'valid::email');
     # if Post is good, atttempt to log owner in.
     if ($post->validate()) {
         $owner = ORM::factory('owner')->find($_POST['email']);
         if (!$owner->loaded) {
             die('email does not have an account');
         }
         $pw = text::random('alnum', 8);
         $owner->password = $pw;
         $owner->save();
         $replyto = 'unknown';
         $body = "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda";
         # to do FIX THE HEADERS.
         $subject = 'Your Pluspanda Password Has Been Reset =)';
         $headers = "From: noreply@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion();
         mail($_POST['email'], $subject, $body, $headers);
         die('Please check your email for your new password!');
     }
     # error
     $login_shell->content->alert = alerts::display(array('error' => 'Invalid Email or Password.'));
     $login_shell->content->values = $_POST;
     die($login_shell);
 }
开发者ID:plusjade,项目名称:pluspanda-php,代码行数:35,代码来源:login.php

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

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

示例7: _get_valid_accinfo

 private function _get_valid_accinfo($old_pass)
 {
     $form = array('txt_old_pass' => '', 'txt_new_pass' => '', 'txt_cf_new_pass' => '', 'txt_email' => '');
     $errors = $form;
     if ($_POST) {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         if (!empty($old_pass)) {
             $post->add_rules('txt_new_pass', 'required', 'length[6,50]');
             $post->add_rules('txt_cf_new_pass', 'matches[txt_new_pass]');
             $post->add_callbacks('txt_old_pass', array($this, '_check_old_pass'));
         }
         $post->add_rules('txt_email', 'required', 'email');
         $post->add_callbacks('txt_email', array($this, '_check_email'));
         if ($post->validate()) {
             $form = arr::overwrite($form, $post->as_array());
             return $form;
         } else {
             $form = arr::overwrite($form, $post->as_array());
             $this->session->set_flash('input_data', $form);
             $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);
             url::redirect($this->uri->segment(1));
             die;
         }
     }
 }
开发者ID:vobinh,项目名称:PHP,代码行数:33,代码来源:admin_myaccount.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: index

 public function index()
 {
     $this->template->content = new View('admin/flickrwijit_form');
     // setup and initialize form field names
     $form = array('flickr_tag' => '', 'flickr_id' => '', 'num_of_photos' => '', 'image_width' => '', 'image_height' => '', 'block_position' => '', 'enable_cache' => '', 'block_no_photos' => '');
     //  Copy the form as errors, so the errors will be stored with keys
     //  corresponding to the form field names
     $errors = $form;
     $form_error = FALSE;
     $form_saved = FALSE;
     // check, has the form been submitted, if so, setup validation
     if ($_POST) {
         // Instantiate Validation, use $post, so we don't overwrite $_POST
         // fields with our own things
         $post = new Validation($_POST);
         // Add some filters
         $post->pre_filter('trim', TRUE);
         $post->add_rules('flickr_tag', 'required', 'length[0,500]');
         $post->add_rules('flickr_id', 'length[0,20]');
         $post->add_rules('num_of_photos', 'numeric');
         $post->add_rules('image_width', 'length[2,600]', 'numeric');
         $post->add_rules('image_height', 'required', 'length[2,600]', 'numeric');
         $post->add_rules('block_position', 'length[1,6]', 'numeric');
         $post->add_rules('enable_cache', 'between[0,1]', 'numeric');
         $post->add_rules('block_no_photos', 'between[4,10]', 'numeric');
         // passed validation test.
         if ($post->validate()) {
             $flickrwijit_settings = new Flickrwijit_Model(1);
             $flickrwijit_settings->flickr_tag = $post->flickr_tag;
             $flickrwijit_settings->flickr_id = $post->flickr_id;
             $flickrwijit_settings->num_of_photos = $post->num_of_photos;
             $flickrwijit_settings->image_height = $post->image_height;
             $flickrwijit_settings->image_width = $post->image_width;
             $flickrwijit_settings->block_position = $post->block_position;
             $flickrwijit_settings->enable_cache = $post->enable_cache;
             $flickrwijit_settings->block_no_photos = $post->block_no_photos;
             $flickrwijit_settings->save();
             // Delete Settings Cache
             // $this->cache->delete('settings');
             // $this->cache->delete_tag('settings');
             // Everything is A-Okay!
             $form_saved = TRUE;
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
         } else {
             // repopulate the form fields
             $form = arr::overwrite($form, $post->as_array());
             // populate the error fields, if any
             $errors = arr::overwrite($errors, $post->errors('flickrwijit'));
             $form_error = TRUE;
         }
     } else {
         $flickrwijit_settings = ORM::factory('flickrwijit', 1);
         $form = array('flickr_tag' => $flickrwijit_settings->flickr_tag, 'flickr_id' => $flickrwijit_settings->flickr_id, 'num_of_photos' => $flickrwijit_settings->num_of_photos, 'image_width' => $flickrwijit_settings->image_width, 'image_height' => $flickrwijit_settings->image_height, 'block_position' => $flickrwijit_settings->block_position, 'enable_cache' => $flickrwijit_settings->enable_cache, 'block_no_photos' => $flickrwijit_settings->block_no_photos);
     }
     $this->template->content->form = $form;
     $this->template->content->errors = $errors;
     $this->template->content->form_error = $form_error;
     $this->template->content->form_saved = $form_saved;
 }
开发者ID:eyedol,项目名称:flickrwijit,代码行数:60,代码来源:flickrwijit.php

示例10: 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

示例11: 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

示例12: index

 public function index()
 {
     $this->__set_heading("Profile");
     $view = new View('zest/content');
     if ($_POST) {
         $post = new Validation($_POST);
         $post->add_rules('email', 'required', 'email');
         if ($post->validate()) {
             $this->user->email = $post['email'];
             $this->user->openid = $post['openid'];
             if (isset($post['password']) && trim($post['password'][0]) != "") {
                 if ($post['password'][0] == $post['password'][1]) {
                     $this->user->password = $post['password'][1];
                 } else {
                     $this->throw_error("Both passwords bust be the same");
                 }
             }
             $this->user->save();
             $this->__throw_success("Your profile has been updated");
         } else {
             $this->throw_error("There has been an error updating your profile, please try again");
         }
     }
     $view->content = $this->_form($this->user);
     $this->__set_content($view);
 }
开发者ID:sydlawrence,项目名称:SocialFeed,代码行数:26,代码来源:profile.php

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

示例14: rename

 public function rename($id)
 {
     access::verify_csrf();
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded) {
         kohana::show_404();
     }
     // Don't use a form as the form is dynamically created in the js
     $post = new Validation($_POST);
     $post->add_rules("name", "required", "length[1,64]");
     $valid = $post->validate();
     if ($valid) {
         $new_name = $this->input->post("name");
         $new_tag = ORM::factory("tag")->where("name", $new_name)->find();
         if ($new_tag->loaded) {
             $error_msg = t("There is already a tag with that name");
             $valid = false;
         }
     } else {
         $error_msg = $post->errors();
         $error_msg = $error_msg[0];
     }
     if ($valid) {
         $old_name = $tag->name;
         $tag->name = $new_name;
         $tag->save();
         $message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name));
         message::success($message);
         log::success("tags", $message);
         print json_encode(array("result" => "success", "location" => url::site("admin/tags"), "tag_id" => $tag->id, "new_tagname" => html::clean($tag->name)));
     } else {
         print json_encode(array("result" => "error", "message" => (string) $error_msg));
     }
 }
开发者ID:scarygary,项目名称:gallery3,代码行数:34,代码来源:admin_tags.php

示例15: 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


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