Reputation: 493
Am using codeigniter version (2.1.4). Am asking if the validation library provides a solution to access validation errors as an array instead of validtation_errors() method.
Regards
Upvotes: 1
Views: 130
Reputation: 21
I don't know if it works in your specified version but in the latest version you can use
$this->form_validation->error_array()
and pass that to view or even better post your form as ajax request and get error messages as array back. You don't need to initialize form helper unless you are using other form elements
Upvotes: 2
Reputation: 3213
You can use the validation_errors() to show all the errors in one place or you can show each error message with respective field in the following way.
<?php echo form_error('username'); ?>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />
and also you can change the error delimiters.
Global delimiters.
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
Individual delimiters.
<?php echo form_error('field name', '<div class="error">', '</div>'); ?>
Or:
<?php echo validation_errors('<div class="error">', '</div>'); ?>
So i dont think you should have a need to get validation errors in an array.
Upvotes: 1
Reputation: 64476
You need to extend the form validation library CI_Form_validation
define your function validation_error_array
variable $this->_error_array
will have the all the errors
class MY_Form_validation extends CI_Form_validation
{
function validation_error_array()
{
return $this->_error_array;
}
}
Upvotes: 2