Tomek Buszewski
Tomek Buszewski

Reputation: 7935

Codeigniter's is_unique doesn't work with multiple fields

I'm making registration form, and I want fields nick and e-mail to be unique. I use form validation in controller:

  $this->load->library('form_validation');
    $this->form_validation->set_rules('nick', '<b>Nazwa użytkownika</b>', 'required|is_unique[users.nick]');
    $this->form_validation->set_rules('email', '<b>Adres e-mail</b>', 'required|is_unique[users.mail]');
    $this->form_validation->set_rules('password', '<b>Hasło</b>', 'required');
    $this->form_validation->set_message('is_unique', '%s jest już w bazie.');

    if ($this->form_validation->run()) {
        $data['submit'] = $this->users_model->CreateUser($this->input->post()); //submits data
        $this->load->view('contribute/emptyPage', $data); //loads view
    } else {
        $data['title'] = 'Załóż konto';
        $this->layout->view('account/create',$data);
    }

It works when I fill only one field, eq. nick or mail. When I fill the whole form, it processes without a problem. Whan can I do?

edit.

I found out that problem occures only when one or more of the fields have only numbers in it.

Upvotes: 0

Views: 3938

Answers (2)

Jacky Supit
Jacky Supit

Reputation: 567

I have created an is_unique function here

You can use it in 2 ways:

//is_unique[table_name.field_to_check.id_field_name.id_field_value] <-- unique 1 field only
//is_unique[table_name.field_to_check.id_field_name != 'id_field_value' and anotherIdName='theValue'] <-- custom where 

hope it could be usefull for you

Upvotes: 0

Bruce
Bruce

Reputation: 1542

You need to create your own custom validation callback function

Upvotes: 1

Related Questions