One validation callback when using arrays


Is it possible to set validation callback on post array, that it would be called only once?

If I have:

<input type="text" name="birthday[year]" value="" />
<input type="text" name="birthday[month]" value="" />
<input type="text" name="birthday[day]" value="" />

$val->set_rules('birthday', 'Birthday', required|callback__birthday_check');

_birthday_check is called three times each time passing same array, and if I use "birthday[]" instead of "birthday" in set_rules then _birthday_check not called at all.

Please do not suggest not using arrays or doing validation for each field separately. This is just an example. If i had a big checklist, which should be validate using database, multiple callbacks would execute many SQL queries.

Thank you for your help :-)

I don't really understand what you are trying to do, but it seems to me you are mistaking how this is supposed to work.

To me, validation is intended to work against each field individually. If you would like to do them all as a single form check, write your own function that does what you need, and then fail the validation if something fails.

Can you give a more detailed example of what you are after?

I understand the what ur trying to do

I used this and worked so u also try it
In Controller
                     'field'   => 'nric[1]',
                     'label'   => 'NRIC(Part1)',
                     'rules'   => 'trim|exact_length[6]'
                     'field'   => 'nric[2]',
                     'label'   => 'NRIC(Part2)',
                     'rules'   => 'trim|exact_length[2]'
                     'field'   => 'nric[3]',
                     'label'   => 'NRIC(Part3)',
                     'rules'   => 'trim|exact_length[4]'
                     'field'   => 'nric[]',
                     'label'   => 'NRIC',
                     'rules'   => 'required'

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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