When form_validation->run()
returns FALSE
, I need to know which rule didn't pass the validation test.
I know I can echo form_error()
or validation_errors()
, but this needs to be done before a view is loaded.
The controller needs to act differently according to which input didn't pass the validation.
Example:
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run())
{
$this->load->view('something');
}
else
{
//check which rule didn't pass and act accordingly
}
}
I tried using empty
on form_error('something')
from within the if
statement but this returns an error as empty
doesn't take functions.
Also note, I can't change the error delimiters because they are used elsewhere in the script.
How would I check which rule was triggered without echoing validation_errors()
?