As the subject say… How to set form validation rules to whole form instead of form field in code-igniter ?
// Définir les règles de validation du formulaire de création de compte
$this->form_validation->set_rules('username', 'Nom d\'usagé', 'required');
$this->form_validation->set_rules('password', 'Mot de passe', 'required|callback_authentification_check');
Consider this code above.. it call callback_authentification_check to check if username and password match.. however it SHOULDNT be attached to the password field since this is an overall form validation process.
So what is the best way to do this ?
Thanks!
Simply put, let the normal form validation rules run, then run your “callback” after the fields have been checked for validity, instead of as a form validation rule:
However:
There’s nothing “wrong” with the way you’re doing it now, but I see your concern. Validation rules run in the order they are defined, so if you run your callback last, you’ll be sure that you’re dealing with “valid” data as defined by your previous rules. You can still access the other
$_POSTdata from there.