[quote name='clare' timestamp='1325679417' post='220']
Hi,
Is there any way to have different validation rules for insert and update? For example, I want the usernames to be unique, but if i do
$this->grocery_crud->set_rules('username', 'Username','trim|required|xss_clean|is_unique[Users.username]');
it doesn't allow me to update the record because it thinks the username is being duplicated...
Thanks
[/quote]
The only way you can do it now without hacking the core is this:
function your_function($operation = null)
{
....
$this->grocery_crud->....
if( $operation == 'insert_validation' || $operation == 'insert')
{
$this->grocery_crud->set_rules('username', 'Username','trim|required|xss_clean|is_unique[Users.username]');
}
else
{
$this->grocery_crud->set_rules('username', 'Username','trim|required|xss_clean');
}
$this->grocery_crud->....
$output = $this->grocery_crud->render();
....
}
I know this is not the best solution, but it will work for sure .
The best thing for me to do its to use custom callback for the set_rule. You can see more at: http://codeigniter.com/user_guide/libraries/form_validation.html#callbacks