I have a code for form validating in my CodeIgniter app:
$this->load->library('form_validation');
$this->form_validation->set_rules('message', 'Message', 'trim|xss_clean|required');
$this->form_validation->set_rules('email', 'Email', 'trim|valid_email|required');
if($this->form_validation->run() == FALSE)
{
// some errors
}
else
{
// do smth
$response = array(
'message' => "It works!"
);
echo json_encode($response);
}
The form is AJAX-based, so frontend have to receive a JSON array with form errors, for example:
array (
'email' => 'Bad email!',
'password' => '6 symbols only!',
)
How to get such list or array with form validation errors in CodeIgniter?