输入的自定义错误消息

时间:2013-05-08 10:33:25

标签: php codeigniter

我正在尝试为输入设置自定义消息:

$this->form_validation->set_message('username', 'Choose a business, Mang!');

并显示:

<?php echo form_error('username'); ?>

但是什么都没有显示给我,有什么不对?

这是我需要的吗?示例:

if($result)
{
    $this->form_validation->set_message('username', 'Choose a business, Mang!');
}

1 个答案:

答案 0 :(得分:0)

您需要设置规则:

$this->form_validation->set_rules('form_field_username', 'username', 'required|callback_business_check');

function business_check($username) {
    if(strlen($this->input->post('form_field_business')) == 0) {
        $this->form_validation->set_message('business_check', 'Choose a business, Mang!');
        return false;
    }
    return true;
}

这提供了我对你正在做的事情的正确认识......