One validation callback when using arrays

#1
[eluser]Unknown[/eluser]
Hello,

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

If I have:

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

Code:
$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 :-)

#2
[eluser]jmadsen[/eluser]
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?

#3
[eluser]vamsee[/eluser]
I understand the what ur trying to do

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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