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


PHP Validation类代码示例

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


在下文中一共展示了Validation类的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.');
         }
     }
 }
开发者ID:jmhobbs,项目名称:q-aargh,代码行数:28,代码来源:island.php

示例2: unique_identity

 /**
  * Triggers error if identity exists.
  * Validation callback.
  *
  * @param	Validation	Validation object
  * @param	string	  field name
  * @return	void
  */
 public function unique_identity(Validation $validation, $field)
 {
     $identity_exists = (bool) DB::select(array('COUNT("*")', 'total_count'))->from($this->_table_name)->where('identity', '=', $validation['identity'])->and_where('provider', '=', $validation['provider'])->execute($this->_db)->get('total_count');
     if ($identity_exists) {
         $validation->error($field, 'identity_available', array($validation[$field]));
     }
 }
开发者ID:rukku,项目名称:SwiftRiver,代码行数:15,代码来源:identity.php

示例3: register

 public function register($name, $password, $password2, $email)
 {
     if ($password != $password2) {
         throw new UserError('Heslo sa nezhoduje.');
     }
     //overenie spravneho tvaru hesla
     $validation = new Validation();
     $validation->checkPasswordLength($password);
     //aktualny cas
     $date = new DateTime();
     $time = $date->getTimestamp();
     //activation key
     $key = md5(uniqid(rand(), true));
     //data pre DB
     $user = array('name' => $name, 'password' => $this->returnHash($password), 'registration_date' => $time, 'last_visit' => $time, 'email' => $email, 'activation_key' => $key);
     //vlozenie dat do DB
     try {
         Database::insert('users', $user);
     } catch (PDOException $error) {
         throw new UserError('Zadané meno alebo email sa už používa');
     }
     //odoslanie aktivacneho emailu
     try {
         $emailSender = new EmailSender();
         $message = 'Dobrý deň,<br><br>';
         $message .= 'pre dokončenie Vašej registrácie na stránke www.tomasblazy.com kliknite na nasledujúci link:<br><br>';
         $message .= 'www.tomasblazy.com/registracia/' . $name . '/' . $key . '<br><br>';
         $message .= 'V prípade, že ste o žiadnu registráciu nežiadali, tento email ignorujte.<br><br>';
         $message .= 'Ďakujeme<br><br>Tím CodingBlog<br><a href="http://tomasblazy.com">tomasblazy.com</a>';
         $emailSender->send($email, 'Aktivácia účtu na Coding Blog', $message, 'CodingBlog', 'noreply@tomasblazy.com');
     } catch (PDOException $error) {
         throw new UserError($error->getMessage(), 'warning');
     }
 }
开发者ID:tomas3093,项目名称:cms-blog,代码行数:34,代码来源:UserManager.php

示例4: 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');
     $this->unvalidatedFields = array('survey_attribute_id', 'website_id', 'default_text_value', 'default_float_value', 'default_int_value', 'default_date_start_value', 'default_date_end_value', 'default_date_type_value', 'control_type_id');
     return parent::validate($array, $save, array());
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:7,代码来源:survey_attributes_website.php

示例5: pdoEditModelAction

 public function pdoEditModelAction($id)
 {
     $this->_view->title = 'Model Edit Form';
     $this->_view->link = base_url() . 'pdo-database/pdo-model/pdo-edit-model/' . $id;
     $users = new Users();
     $row = $users->get($id);
     if (empty($row)) {
         redirect('pdo-database/pdo-model/pdo-model');
     }
     $this->_view->data = $row;
     if (!empty($_POST)) {
         $val = new Validation();
         $val->source = $_POST;
         $val->addValidator(array('name' => 'first_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'last_name', 'type' => 'string', 'required' => true));
         $val->addValidator(array('name' => 'email', 'type' => 'email', 'required' => true));
         $val->addValidator(array('name' => 'address', 'type' => 'string', 'required' => true));
         $val->run();
         if (sizeof($val->errors) == 0) {
             $data = array('first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'email' => $_POST['email'], 'address' => $_POST['address']);
             $users->update($id, $data);
             redirect('pdo-database/pdo-model/pdo-model');
         }
         $this->_view->errorMessage = $val->errorMessage();
         $this->_view->data = $_POST;
     }
     $this->renderView('pdo-database/pdo-model/_form');
 }
开发者ID:ngukho,项目名称:mvc-cms,代码行数:28,代码来源:PdoModelController.php

示例6: index

 public function index()
 {
     if ($this->auth->logged_in()) {
         $this->template->title = 'Already Logged In';
         $this->template->content = new View('login/login_message');
         $this->template->content->message = 'You are already logged in.<br />';
         $this->template->content->link_to_home = 'YES';
         $this->template->content->link_to_logout = 'YES';
         return;
     }
     $this->template->title = 'Forgotten Password Email Request';
     $this->template->content = new View('login/forgotten_password');
     if (request::method() == 'post') {
         $post = new Validation($_POST);
         $post->pre_filter('trim', TRUE);
         $post->add_rules('UserID', 'required');
         $returned = $this->auth->user_and_person_by_username_or_email($_POST['UserID']);
         if (array_key_exists('error_message', $returned)) {
             $this->template->content->error_message = $returned['error_message'];
             return;
         }
         $user = $returned['user'];
         $person = $returned['person'];
         if (!$this->check_can_login($user)) {
             return;
         }
         $this->auth->send_forgotten_password_mail($user, $person);
         $this->template->title = 'Email Sent';
         $this->template->content = new View('login/login_message');
         $this->template->content->message = 'An email providing a link which will allow your password to be reset has been sent to the specified email address, or if a username was provided, to the registered email address for that user.<br />';
     }
 }
开发者ID:BirenRathod,项目名称:indicia-code,代码行数:32,代码来源:forgotten_password.php

示例7: get_fieid_attribute

 public static function get_fieid_attribute(Validation $val, $name, $default_value = null, $is_textarea = false, $optional_attr = array())
 {
     $field = $val->fieldset()->field($name);
     $label = '';
     $input_attr = array();
     $is_required = false;
     if (is_callable(array($field, 'get_attribute'))) {
         $input_attr = $field->get_attribute();
         $input_attr = Arr::filter_keys($input_attr, array('validation', 'label'), true);
         if ((is_null($default_value) || empty($default_value) && !strlen($default_value)) && !is_null($field->get_attribute('value'))) {
             $default_value = $field->get_attribute('value');
         }
         $is_required = $field->get_attribute('required') == 'required';
         $label = $field->get_attribute('label');
     }
     if (!is_array($optional_attr)) {
         $optional_attr = (array) $optional_attr;
     }
     if ($optional_attr) {
         $input_attr += $optional_attr;
     }
     if (empty($input_attr['id'])) {
         $input_attr['id'] = Site_Form::get_field_id($name);
     }
     if (empty($input_attr['class'])) {
         $input_attr['class'] = 'form-control';
     }
     return array($default_value, $label, $is_required, $input_attr);
 }
开发者ID:uzura8,项目名称:flockbird,代码行数:29,代码来源:form.php

示例8: validate

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

示例9: register

 function register()
 {
     global $timezones;
     $this->pageTitle = __('register', true);
     $this->set('tzs', $timezones);
     $this->set('utz', $this->data['User']['tz']);
     if (!empty($this->data)) {
         $this->Security->requirePost('register');
         $v = new Validation();
         if ($this->data['User']['email'] !== $this->data['User']['confemail']) {
             $this->User->invalidate('confemail');
         }
         if ($this->User->findByEmail($this->data['User']['email']) || !$v->email($this->data['User']['email'])) {
             $this->User->invalidate('email');
         }
         if ($this->data['User']['password'] !== $this->data['User']['confpass']) {
             $this->User->invalidate('confpass');
         }
         if (!$v->url($this->data['User']['website']) && !empty($this->data['User']['website'])) {
             $this->User->invalidate('website');
         }
         if ($this->User->validates()) {
             $clean = new Sanitize();
             // Generate and set the password, salt and activation key
             $pass = $this->Hash->password($this->data['User']['password'], $this->data['User']['email']);
             $this->data['User']['active'] = $this->Hash->keygen(10, true);
             $this->data['User']['password'] = $pass['pass'];
             $this->data['User']['salt'] = $pass['salt'];
             // Save a few fields from the wrath of cleanArray()
             $temp = array('lat' => $this->data['User']['lat'], 'lng' => $this->data['User']['lng'], 'tz' => $this->data['User']['tz'], 'email' => $this->data['User']['email']);
             // Scrub 'a dub
             $clean->clean($this->data);
             $this->data['User']['email'] = $clean->escape($temp['email']);
             $this->data['User']['lng'] = floatval($temp['lng']);
             $this->data['User']['lat'] = floatval($temp['lat']);
             $this->data['User']['tz'] = intval($temp['tz']);
             $this->data['User']['role'] = 0;
             $this->User->begin();
             if ($this->User->save($this->data)) {
                 $this->Email->to = $this->data['User']['email'];
                 $this->Email->replyTo = $this->data['User']['email'];
                 $this->Email->from = APP_NAME . ' <' . APP_EMAIL . '>';
                 $this->Email->subject = sprintf(__('email_subject_welcome', true), APP_NAME);
                 $this->Email->template = 'register';
                 $this->Email->sendAs = 'both';
                 $this->set('actcode', $this->data['User']['active']);
                 if ($this->Email->send()) {
                     $this->User->commit();
                     $this->Session->setFlash('Account created!');
                 } else {
                     $this->User->rollback();
                     $this->Session->setFlash('Error!');
                 }
             } else {
                 $this->User->rollback();
                 $this->Session->setFlash('Error\'d');
             }
         }
     }
 }
开发者ID:rhencke,项目名称:mozilla-cvs-history,代码行数:60,代码来源:users_controller.php

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

示例11: validate

 public function validate(CM_Form_Abstract $form)
 {
     if ($this->_extra_validation) {
         $values = array();
         foreach ($form->get_values() as $name => $value) {
             $values[$name] = $value->get_raw();
             $this->_extra_validation->label($name, $form->get_field($name)->get_label());
         }
         // Validation только read-only, поэтому создаем новый объект
         $this->_extra_validation = $this->_extra_validation->copy($values);
     }
     try {
         $this->get_model()->check($this->_extra_validation);
     } catch (ORM_Validation_Exception $e) {
         $errors = $e->errors('validation');
         if ($external = arr::get($errors, '_external')) {
             $errors = arr::merge($errors, $external);
             unset($errors['_external']);
         }
         foreach ($errors as $name => $error) {
             $form->get_field($name)->set_error($error);
         }
         return FALSE;
     }
     return TRUE;
 }
开发者ID:ariol,项目名称:adminshop,代码行数:26,代码来源:ORM.php

示例12: valid

function valid($action = 'moderator', $no = 0)
{
    require_once CORE_DIR . "/admin/validate.php";
    $validate = new Validation();
    $allowed = $validate->verify($action);
    return $allowed;
}
开发者ID:ru4chan,项目名称:yotsubato,代码行数:7,代码来源:admin.php

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

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

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


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