Welcome Guest, Not a member yet? Register   Sign In
Form Validation: how can get all the error messages as name value pairs?
#1

[eluser]sabya[/eluser]
Sorry if its a n00b question.
Is there any way so that I can get error messages in name value pair?
So say in an example form there are four fields: 'user_name', 'password', 'password_conf', 'timezone'.

Among them 'user_name', 'password' validation has failed.
So after executing: -
Code:
$this->form_validation->run()

If the above function returns false, I want to get the errors in name value pairs like:
Code:
Array
{
  'user_name' => 'user name is required',
  'password' => 'passord is required'
}
Actually, I want to form a JSON, which I can pass back to the AJAX call.
I have a solution (a dirty one):-

I can call validation methods one by one like: -
Code:
$this->form_validation->required($user_name);
$this->form_validation->required($password);

Is there any other way, to get all the error messages *at once* in name value pair?




Theme © iAndrew 2016 - Forum software by © MyBB