Codeigniter - edit form (repopulating) with edit_unique

a 夏天 提交于 2019-12-02 03:41:29

问题


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

All works fine, which something like this...

echo form_input('username', set_value('username',$user->username));

But when using the edit_unique validation, the value is empty after submitting the form. Post-Variables are ok and also the validation has no errors - but the value is not set.

Any idea how I can fix that?


回答1:


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;
    }
}


来源:https://stackoverflow.com/questions/15928650/codeigniter-edit-form-repopulating-with-edit-unique

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!