好吧,我不知道什么是不工作。我知道我的表单验证工作正常,因为我所有的其他函数都能正常工作,但我设置的消息是否为真或假,并且没有一个显示出来,所以我觉得它正在跳过验证规则,这很奇怪。 。CodeIgniter num_rows()不起作用?
$this->form_validation->set_rules('region', 'required|valid_region');
我的库文件夹中的MY_Form_validation.php规则。库首先被加载。正如我所说的,我所有的其他验证都正常工作,例如我的reCaptcha和所有内容。
function valid_region($str) {
$this->load->database();
if($this->db->query('SELECT id
FROM region
WHERE name = ?
LIMIT 1', array($str))->num_rows() == 0) {
//not a valid region name
$this->set_message('valid_region', 'The %s field does not have a valid value!');
return false;
}
$this->set_message('valid_region', 'Why is it validating?');
}
无消息都会将让我有一种感觉,没有什么是验证!
http://stackoverflow.com/questions/8181779/creating-a-custom-codeigniter-validation-rule –