required_fields.. question....
- Single Page
Posted 10 May 2012 - 19:05 PM
any ideas??
Posted 10 May 2012 - 19:10 PM
function just_a_test($operation = '')
{
$crud = new grocery_CRUD();
if($operation != 'edit' && $operation != 'update' && $operation != 'update_validation')
$crud->required_fields('first_name','last_name');
else
$crud->required_fields('last_name');
$crud->set_table('your_table');
$output = $crud->render();
....
}
or something similar you get the point
Posted 10 May 2012 - 19:19 PM
the reason why is because in the add forn I had "password" field , and in edit form If password is blank, do not update that field. Do you get the idea?
I was usign this to acomplish it:
$crud->add_fields('username','email','password','password_confirm','first_name','last_name','phone','grupos');
$crud->edit_fields('username','email','edit_password','edit_password_confirm','first_name','last_name','phone','grupos');
$crud->required_fields('username','email','first_name','last_name','phone','grupos','password','password_confirm');
so in the edit form the edit_ fields do not exists in the db (refering to the bug) so it works....
Posted 10 May 2012 - 20:11 PM
But remember that even if the field WAS at the database the same code will work for you. The required fields checks only if the field is into the add/edit form. Just a tip to know, perhaps you will need it.
The bug is that the change_field_type doesn't work with fields that they are not in the table.
Posted 10 May 2012 - 20:24 PM
if($uri2 != 'edit' && $uri2 != 'update' && $uri2 != 'update_validation'){
$crud->required_fields('username','email','first_name','last_name','phone','grupos','password','password_confirm');
$crud->set_rules('password', 'Password', 'required|min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$crud->set_rules('password_confirm', 'Password Confirmation', 'required');
}else{
$crud->required_fields('username','email','first_name','last_name','phone','grupos');
$crud->set_rules('password', 'Password', 'min_length[' . $this->config->item('min_password_length', 'ion_auth') . ']|max_length[' . $this->config->item('max_password_length', 'ion_auth') . ']|matches[password_confirm]');
$crud->set_rules('password_confirm', 'Password Confirmation', '');
}
So in the edit It is not required... if not blank it works like in the add checking the max/min lenght, so I get rid of the thinking in the return value from the callback that was killing me.
Thanks for the help and the tip.