Codeigniter - edit form (repopulating) with edit_unique

前端 未结 1 1861
忘了有多久
忘了有多久 2021-01-22 02:14

It seems that the edit_unique function, which is desribed here - Validating Uniqueness In CodeIgniter When Updating A Record, kills the set_value funct

相关标签:
1条回答
  • 2021-01-22 02:56

    Ok - found it myself. There was no return value in case of beeing true. Perhaps anyone faces the same problem... with this function, it works:

    function edit_unique($value, $params)  {
        $CI =& get_instance();
        $CI->load->database();
    
        $CI->form_validation->set_message('edit_unique', "Sorry, that %s is already being used.");
    
        list($table, $field, $current_id) = explode(".", $params);
    
        $query = $CI->db->select()->from($table)->where($field, $value)->limit(1)->get();
    
        if ($query->row() && $query->row()->id != $current_id)
        {
            return FALSE;
        } else {
            return TRUE;
        }
    }
    
    0 讨论(0)
提交回复
热议问题