本文整理汇总了PHP中Validation::pre_filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::pre_filter方法的具体用法?PHP Validation::pre_filter怎么用?PHP Validation::pre_filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validation
的用法示例。
在下文中一共展示了Validation::pre_filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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;
}
示例2: 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;
}
示例3: _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;
}
}
}
示例4: validate
public function validate(Validation $array, $save = FALSE)
{
$array->pre_filter('trim');
$array->add_rules('term', 'required');
$array->add_rules('language_id', 'required');
return parent::validate($array, $save);
}
示例5: 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);
}
示例6: 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);
}
示例7: _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;
}
}
}
示例8: _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;
}
}
}
示例9: 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');
}
示例10: 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');
}
示例11: 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;
}
示例12: 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;
}
示例13: 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();
}
示例14: 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;
}
示例15: 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('user_id', 'website_id', 'site_role_id');
return parent::validate($array, $save);
}