Form Validation -> Run Rules for a Specific Field


I have a set of validation rules in a config file (like this):

$config = array(
                         'field'   => 'nome',
                         'label'   => $CI->lang->line('form_campo_nome'),
                         'rules'   => 'required|alpha|callback_vnome'
                         'field'   => 'apelido',
                         'label'   => $CI->lang->line('form_campo_apelido'),
                         'rules'   => 'required|alpha'
                         'field'   => 'sexo',
                         'label'   => $CI->lang->line('form_campo_sexo'),
                         'rules'   => 'required'

In my controller, inside a callback function for a specific field I want to run validation rules of another field.
Is it possible? How?

Some more explanation: In the callback my aplication access to an external webservice to perform some additional validation, as this service has a big delay I only want to execute it if the other field is valid

I hope you understand my problem.

Thanks in advance..

I forgot to say that I solved this problem repeating the rules in my controller. However I really don't appreciate this solution, because in the future someone could update the config rules!

Hi Pedro,

I'm doing some similar soul-searching at the moment with my validation sequences.

Was your problem made worse here by the single big config of validations - could you get around it by doing a sequential check on the easy/local lookups first, and then call in another validation->set_rules/run if that one passes?

I'm not sure what you mean when you say that you had to replicate the rules in the controller - where was the original rule set kept?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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