[eluser]Unknown[/eluser]
The below code doesn't work. I'm trying to prevent the user from deleting more than 25% of a block of text at one time.
However, for some reason if I pass the $id as the 2nd parameter to my_min_length() and then get the old text within the function, it works fine.
I don't want to do that though because I need to add 2 more custom rules which will also require the old text so I would need to make additional db calls.
Thanks in advance for any help.
Code:
function my_min_length($new_text, $old_text)
{
// SET MAX DELETE PERCENT:
$max_delete = .25;
// Test and return
if (strlen($new_text) < strlen($old_text)*(1-$max_delete))
{
$this->form_validation->set_message('my_min_length', 'You can not delete
more than 25% of the text at one time.');
return FALSE;
}
else
{
return TRUE;
}
}
function validate_new_text($id) {
// Get old text
$old_text = $this->Maintenance_model->get_old_text($id);
// Set rules
$this->form_validation->set_rules('new_text', 'New Text', "trim|required|callback_my_min_length[$old_text]");
return $this->form_validation->run();
}