• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Distinct form errors from an array of post data

#1
[eluser]gwerner[/eluser]
I have a form that I'm using to set hours for locations. The form is generated from a foreach loop for each of the seven days of the week. I was hoping to be able to set individual errors for any field that is left empty. The form consists of two drop downs and one checkbox for each day of the week. The checkboxes are allowed to be checked or not checked, so they aren't really important to this issue.

The drop down values will match mysql time (00:00:00). The error that could occur is if the user doesn't select a time. That value is 0. I have my own validation rule written that checks for this. The problem is that if a user leaves any one of these drop downs in the default state the error will show for all 7 drop downs even though only one is incorrect.

Is there a way to match the form error to the exact field that was left unchanged?

Code:
<?php echo form_dropdown('open[]', build_hours(), set_value('open[]', $value['hours_open']), 'id="open[]"'); ?><?php echo form_error('open[]'); ?>

Statndard validation check below. How can I match this array field to the array field on the form page?
Code:
$this->form_validation->set_rules('open[]', 'Open', 'required|valid_time_stamp');


This is the result I'm getting because in the _error_array it shows up as open[] without any key to match.

MONDAY -error
TUESDAY -error
WEDNESDAY -error
THURSDAY -error
FRIDAY -error
SATURDAY -error
SUNDAY -error

The result I'm hoping to achieve if the user forgets to select an open option in the form. (Friday for this example, but it could be any number of day or days)

MONDAY -
TUESDAY -
WEDNESDAY -
THURSDAY -
FRIDAY -error
SATURDAY -
SUNDAY -


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.