function display_grid(){
$this->load->library('form_validation');
$data['titulo'] = "Tabla de elementos";
$data['contenido'] = 'cms_elementos_grid';
$crud = new grocery_CRUD();
$crud->set_subject('usuario');
$crud->set_table('usuarios');
$crud ->columns('id', 'email', 'tipo', 'estado', 'creado_en');
$crud ->fields('email', 'clave', 'vclave','tipo', 'estado');
$crud->display_as('vclave', 'Verificar Clave');
$crud->change_field_type('clave', 'password');
$crud->change_field_type('vclave', 'password');
$crud->required_fields('email', 'clave','vclave', 'tipo');
$crud->set_rules('email', 'Correo Electronico', 'valid_email|callback_username_check'); <---- at updating throws email already exists message as declared on callback ..
$crud->set_rules('clave', 'Clave', 'required|trim|max_length[20]');
$crud->set_rules('vclave', 'Verificar Clave', 'required|trim|matches[clave]|max_length[20]');
$crud->callback_before_insert(array($this,'unset_vclave'));
$crud->callback_before_insert(array($this,'encriptar_clave')); <-----THIS ONE RUN
$output = $crud->render();
$data['tablecrud'] = $output;
$this->load->view('cms_plantilla',$data);
}
function username_check($str)
{
$num_row = $this->db->where('email', $str)->get('usuarios')->num_rows();
if($num_row > 0)
{
$this->form_validation->set_message('username_check', 'El email ya existe en el sistema');
return FALSE;
}
else
{
return TRUE;
}
}
function unset_vclave($post_array){
unset($post_array['vclave']);
return $post_array;
}
function encriptar_clave($post_array){
$post_array['clave'] = substr(do_hash($post_array['clave']),0,16);
//print_r($post_array);
return $post_array;
}
callback_before_insert issue
- Single Page
Posted 19 November 2012 - 17:10 PM
Posted 19 November 2012 - 18:21 PM
Posted 19 November 2012 - 18:40 PM
Spasibo /thanks
Posted 19 November 2012 - 18:47 PM
Posted 19 November 2012 - 18:56 PM
Posted 19 November 2012 - 19:05 PM
Posted 19 November 2012 - 19:46 PM
if($crud->getState()=='edit')
{
if($this->input->post('email'))
{
$user_data = $this->db->get_where('your_users_table',array('your_user_id_field'=>$this->input->post('yuur_user_id_field')))->row_array();
if($user_data['email']!=$this->input->post('email'))
{
$crud->set_rules('email', 'Email', 'required|valid_email|is_unique[contacts.email]');
}
}
}
else
{
$crud->set_rules('email', 'Email', 'required|valid_email|is_unique[contacts.email]');
}
Posted 19 November 2012 - 21:32 PM