phpcodeignitervalidation

Using is_unique validation rule with two fields?


I have two input fields in a form. I need to check if both of them are unique in a table in which they are inserted. How can I perform this check in codeigniter.


Solution

  • yes its really easy with CI form validation you need to set is_unique to check unique value in table

    $this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[12]|is_unique[users.username]');
    
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email|is_unique[users.email]');
    

    in above example you can see is_unique table name and column name of table to check unique value as parameter

    here the document link you can read http://www.codeigniter.com/user_guide/libraries/form_validation.html#rulereference