我有一个简单的表单,它使用以下验证规则添加到我的数据库中。“表单”在 autoload.php 中。
每当任何验证规则被破坏时,页面都不会显示错误输出,当没有任何验证规则被破坏时,表单会按预期通过。
这是我的控制器功能
public function add()
{
$this->load->library('form_validation');
$this->load->library('layout');
// field name, error message, validation rules
$this->form_validation->set_rules('type', 'Type', 'required|xss_clean');
$this->form_validation->set_rules('title_type', 'Title type', 'required|xss_clean');
$this->form_validation->set_rules('first_name', 'First name', 'trim|required|min_length[1]|max_length[150]|xss_clean');
$this->form_validation->set_rules('surname', 'Surname', 'trim|required|min_length[1]|max_length[150]|xss_clean');
$this->form_validation->set_rules('job_title', 'Job title', 'trim|min_length[5]|max_length[300]required|xss_clean');
$this->form_validation->set_rules('office_number', 'Office number', 'trim|min_length[2]|max_length[11]|xss_clean');
$this->form_validation->set_rules('telephone', 'Telephone', 'trim|numeric|xss_clean');
$this->form_validation->set_rules('email', 'Email', 'trim|valid_email|xss_clean');
$this->form_validation->set_rules('website', 'Website', 'trim|prep_url|xss_clean');
$this->form_validation->set_rules('background', 'Background', 'trim|xss_clean');
$data = array(
'title' => 'Add staff member'
);
if ($this->form_validation->run() == FALSE) { //Was errors
$this->session->set_flashdata('message','You missed some details, please try again.');
$this->layout->load('default', 'add_person', $data);
} else {
$this->people_model->add_person();
$this->layout->load('default', 'added_person', $data);
}
} //add
在我的表单视图中,我有
<?php echo validation_errors('<p class="msg msg-error">') ?>
谁能看到我做错了什么,我已经尝试了我能想到的一切。
validation_errors() 的 var_dump 给出
string '' (length=0)
编辑:奇怪的是,如果我交换这两行,我得到:
$this->load->library('form_validation');
$this->load->library('layout'); //lib code http://pastebin.com/K1rBV512
Message: Undefined property: People::$form_validation
Filename: controllers/people.php
Line Number: 27