is_unique for codeigniter form validation

前端 未结 9 1051
走了就别回头了
走了就别回头了 2020-12-03 07:19

I\'m trying to figure out how I can use the is_unique rule from the Codeigniter form validation library in the following situation.

I\'m trying to submi

相关标签:
9条回答
  • 2020-12-03 08:00
    $something = $this->input->post('something');
    
    $this->form->validation->set_rules('something','Something','xss_clean|is_unique['tbl'.users]');
    
    if($this->form_validation->run()== FALSE){
    
    }
    
    0 讨论(0)
  • 2020-12-03 08:03

    There's a better way to go around it, I think, still using CodeIgniters' validation library... Use edit_unique where you pass an extra parameter which is the id of the row you're editing.. See below.. I use it and works pretty fine for me.. hope it helps

    $this->form_validation->set_rules('user_name', 'User Name', 'required|trim|xss_clean|edit_unique[users.user_name.'.$id.']');
    
    0 讨论(0)
  • 2020-12-03 08:04

    Simple Way

    Just Change isset to is_object in system/libraries/form_validation.php

    public function is_unique($str, $field)
    {
        sscanf($field, '%[^.].%[^.]', $table, $field);
        return is_object($this->CI->db) //default isset
            ? ($this->CI->db->limit(1)->get_where($table, array($field => $str))->num_rows() === 0)
            : FALSE;
    }
    
    0 讨论(0)
提交回复
热议问题