CodeIgniter Forums
Form validation running multiple groups of rules - 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 running multiple groups of rules (/showthread.php?tid=27532)



Form validation running multiple groups of rules - El Forum - 02-13-2010

[eluser]greedyh4mster[/eluser]
Hiya!

I have several forms. I am using form_validation to store all my rules across all forms. However, I face a problem displaying all the validation errors.

This is what is inside form_validation
Code:
$config = array(
    'login' => array(
            array(
                'field' => 'username',
                'label' => 'lang:username',
                'rules' => 'required|alpha_numeric|trim|xss_clean|callback_check_username'
            ),
            array(
                'field' => 'password',
                'label' => 'lang:password',
                'rules' => 'required|alpha_numeric|trim|xss_clean'
            ),
            array(
                'field' => 'password_conf',
                'label' => 'lang:password_conf',
                'rules' => 'required|alpha_numeric|matches[password]|trim|xss_clean'
            )
        ),
    'register' => array(
            array(
                'field' => 'email_address',
                'label' => 'lang:email_address',
                'rules' => 'required|valid_email|trim|xss_clean|callback_check_email'
            ),
            array(
                'field' => 'person_name',
                'label' => 'lang:person_name',
                'rules' => 'alpha_numeric|trim|xss_clean'
            )
        )
    );

Here is my controller calling the form.
Code:
if($this->form_validation->run('login') && $this->form_validation->run('register')){

In my view for the registration form, I have:
Code:
echo validation_errors();

But it is only echoing out the errors for the rule set: 'auth', but not the errors for the rule set: 'register'.

Please assists.


Form validation running multiple groups of rules - El Forum - 02-17-2010

[eluser]greedyh4mster[/eluser]
Is there anyone who can help with this?

Like having a standard arrays containing all validation rules, but capable of serving for multiple forms?


Form validation running multiple groups of rules - El Forum - 02-17-2010

[eluser]maria clara[/eluser]
instead of

Code:
if($this->form_validation->run('login') && $this->form_validation->run('register')){

try
Code:
if ($this->form_validation->run('login'))
  {

  /*some code here*/
  }


if ($this->form_validation->run('register'))
  {

  /*some code here*/
  }

try to have separate if condition for both validation error


Form validation running multiple groups of rules - El Forum - 02-28-2010

[eluser]greedyh4mster[/eluser]
It seems like the first $this->form_validation->run() is able to run through the validation rules set.

However the second $this->form_validation->run(), is always true even when the data entered by the user is obviously wrong.

Anyone has a solution for running $this->form_validation->run() multiple times for a single form?