Welcome Guest, Not a member yet? Register   Sign In
Form validation running multiple groups of rules
#1

[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.
#2

[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?
#3

[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
#4

[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?




Theme © iAndrew 2016 - Forum software by © MyBB