codeigniter中的Form_validation

时间:2017-12-03 19:40:00

标签: php codeigniter-3

我需要验证字段username.I想在字段为空时显示必需的错误,否则应该调用callback_exist。但它每次都会显示callback_exist的错误消息。

$this->load->library('form_validation');
    $this->load->model('first');
    $config=array
    (
        [   
            'field'=>'username',
            'rules' =>'required|min_length[5]|callback_exist',
            'label'=>'username',
            'errors'=>array(
                'required'=>'its required',
                'min_length'=>'please enter correct',
            )
        ],

    );
    $this->form_validation->set_rules($config);
    if ($this->form_validation->run() == FALSE)
    {

        $this->load->view('form_view');

    }
    else
    {
        $this->load->view('welcome_message');
    }
}


public function exist()
{
    $this->load->library('form_validation');
    $this->form_validation->set_message('exist','dont exists');
    return false;
}

0 个答案:

没有答案