Codeigniter: Form Validation is_unique does't work as expected

Created on 22 Jun 2018  路  1Comment  路  Source: bcit-ci/CodeIgniter

System Information:

Info

If I using form_validation is_unique without loading database It'll always return false.
In the documentation doesn't tell me to load db but I figured it out workaround fix by using $this->load->database(); all works as expected.

Some code in my controller.

        .
        .
        .
        $this->load->database(); // try to comment this and validate, it'll always return false
        $this->load->library('form_validation');
        $this->form_validation->set_data($data);
        $this->form_validation->set_rules(
            'username', 'Username',
            'required|min_length[5]|max_length[30]|is_unique[users.us_name]',
            array(
                'required'      => 'You have not provided %s.',
                'is_unique'     => 'This %s already exists.'
            )
        );
        if ($this->form_validation->run() == FALSE)
        {
            // return some true result
        }
        else
        {
            // return some false result
        }
        .
        .
        .
        .

>All comments

It's common sense that you need to have a database connection in order to perform a database operation ...

Was this page helpful?
0 / 5 - 0 ratings