callback_before_update

void callback_before_update(mixed $callback ) 
Quick Description: This callback runs before the auto update of the crud.

This callback runs before the auto update of the crud. The callback takes as a 1st parameter the post array and as 2nd the primary key value. The return value is not required. Although if you return a value must be an array like a post array. With this opportunity you can add or unset some post variables.

Example:

public function users(){
    $crud = new grocery_CRUD();
    $crud->set_table('db_user');
    $crud->set_subject('User');
    $crud->required_fields('user_name');
 
    $crud->columns('user_name','email','real_name','active', 'groups');
    $crud->fields('user_name','email','password','real_name','active', 'groups');
 
    $crud->callback_edit_field('password',array($this,'set_password_input_to_empty'));
    $crud->callback_add_field('password',array($this,'set_password_input_to_empty'));
 
    $crud->callback_before_update(array($this,'encrypt_password_callback'));
 
    $output = $crud->render();
    $this->_example_output($output);
}
 
function encrypt_password_callback($post_array, $primary_key) {
    $this->load->library('encrypt');
 
    //Encrypt password only if is not empty. Else don't change the password to an empty field
    if(!empty($post_array['password']))
    {
        $key = 'super-secret-key';
        $post_array['password'] = $this->encrypt->encode($post_array['password'], $key);
    }
    else
    {
        unset($post_array['password']);
    }
 
  return $post_array;
}
 
function set_password_input_to_empty() {
    return "<input type='password' name='password' value='' />";
}