Codeigniter - Displaying individual error message for array fields
Looking at the Form Validation documentation, specifically the Using Arrays as Field Names section, I think you're going to need to explicitly name your inputs by including the index in the name to get the form_error()
method to work as you desire.
So in order for form_error('customer_names[0]')
to work, there will actually have to be an input with the name customer_names[0]
.
I was having the same problem with CodeIgniter 2.1.3. I have resolved it like this:
The input is:
<input type="text" name="customer_names[0]" />
<input type="text" name="customer_names[1]" />
...
The form validation is:
$this->form_validation->set_rules('customer_names[0]','Customer Names','required');
$this->form_validation->set_rules('customer_names[1]','Customer Names','required');
...
The errors are displayed like this:
echo form_error('customer_names[0]');
echo form_error('customer_names[1]');
...