CodeIgniter Forums
Form Validation -> Run Rules for a Specific Field - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Form Validation -> Run Rules for a Specific Field (/showthread.php?tid=20023)



Form Validation -> Run Rules for a Specific Field - El Forum - 06-25-2009

[eluser]Multisnet[/eluser]
Hello,

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

Code:
$config = array(
            'registoPaciente'=>array(
                   array(
                         'field'   => 'nome',
                         'label'   => $CI->lang->line('form_campo_nome'),
                         'rules'   => 'required|alpha|callback_vnome'
                      ),
                   array(
                         'field'   => 'apelido',
                         'label'   => $CI->lang->line('form_campo_apelido'),
                         'rules'   => 'required|alpha'
                      ),
                   array(
                         '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..

UPDATE:
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!


Form Validation -> Run Rules for a Specific Field - El Forum - 06-26-2009

[eluser]jedd[/eluser]
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?