Hello guys
I´m using grocery on a project in the last 2 days and it looks very good so far. This is my first question here in the forum =)
My question is: How to make a field required on insert but NOT on update?
The table has a password field that must be filled in the insert, but in the update, if the user leaves the password blank, the system will simply not change it in the table.
I havent found any example of how to do this.
Can you help me? Thanks.
Here is my code
function tb_usuario()
{
$crud = $this->grocery_crud;
$crud->set_theme('twitter-bootstrap');
$crud->unset_print();
$crud->set_rules('email','Email','required|valid_email');
$crud->set_rules('senha','Senha','required');
$crud->set_rules('login','Login','required');
$crud->field_type('senha', 'password');
$crud->callback_edit_field('senha',array($this,'set_password_input_to_empty'));
$crud->callback_add_field('senha',array($this,'set_password_input_to_empty'));
$crud->callback_before_insert(array($this,'encrypt_password_callback'));
$crud->callback_before_update(array($this,'encrypt_password_callback'));
$output = $crud->render();
$tituloPagina = " Gerenciamento de Usuário ";
$this->defaultOutput($output, $tituloPagina);
}
function encrypt_password_callback($post_array) {
if(!empty($post_array['senha']))
{
$post_array['senha'] = md5($post_array['senha']);
}
else
{
unset($post_array['senha']);
}
return $post_array;
}
function set_password_input_to_empty() {
return "<input type='password' name='senha' value='' />";
}