Welcome Guest, Not a member yet? Register   Sign In
Problem with validation an unique field
#11

[eluser]Mr.SoOoMa[/eluser]
Yes, it's working great now Smile

Thanks a lot dude Big Grin
#12

[eluser]CroNiX[/eluser]
Sure. You might try loading your model in your edit_unique_email function, unless it needs to be loaded every time the validation class is used.
#13

[eluser]GrahamDj28[/eluser]
The solution posted here is great for that one situation.
But you will probably run into this problem with other fields and values.

What I did was, extend the Form_validation with MY_Form_validation and then override the original is_unique function and update it with some extra code. Like this

Code:
public function is_unique($str, $field) {
    // Get the id of the record that you are posting
    $id = $this->CI->input->post('id');
    
    // Original code to query the DB
    list($table, $field)=explode('.', $field);
    $query = $this->CI->db->limit(1)->get_where($table, array($field => $str));
    
    // Do we have a result?
    if($query->num_rows() > 0) {
        // Get the results object
        $result = $query->result();
        // Does the id of the result match the id of your post?
        if((int)$result[0]->id === (int)$id) {
            return TRUE; // ID's match, return TRUE
        } else {
            return FALSE; // ID's don't match, return FALSE
        }
    } else { // No result, return TRUE
        return TRUE;
    }
}

This will now always work on any table and any values that are passed to it.

Hope you can use this!




Theme © iAndrew 2016 - Forum software by © MyBB