1

I have got stummped on a problem where I can not see why codeIgniter is ignoring my rules setup in the "form_validation.php" in which i am using the following code.

$config = array(
'racedetails' => array(
    array(
        'field' => 'race_memberno',
        'label' => 'MembershipNumber',
        'rules' => 'required' 
    ),
    array(
        'field' => 'race_penalties',
        'label' => 'Penalties',
        'rules' => 'required' 
    )
);

I am then calling the Validation set on my controller using:

$this->form_validation->run('racedetails');

However it always states false when ran, The form runs normal and returns no errors , Is there somthing else I may have missed ?

The Above Validation run function runs within the following (Requested by Dale)

public function index($id){
    $this->load->library('form_validation');
    if($this->form_validation->run('racedetails')){$validated++;} 

    if($validated != 1){
        $this->process_template_build('entries/entry',$data);
    }else {
      echo "Validation Passed";
    }
}
3
  • Could you post the code for the method that this lies within? Commented Jul 19, 2012 at 12:02
  • Did you try $this->form_validation->run($config['racedetails'])? Commented Jul 19, 2012 at 12:06
  • Yan - Yes did try with the $config put it just returns a undefined variable. Commented Jul 19, 2012 at 12:14

2 Answers 2

1

I had the same problem and the reason was, that I´m using an own Form_validation class to stlye the error output globally.

There I forgot to pass the rules to the parent constructor. So this is how it works with an own MY_Form_Validation class:

class MY_Form_validation extends CI_Form_validation {

public function __construct($rules = array())
{
    parent::__construct($rules);

    $this->_error_prefix = '<div class="alert alert-danger" role="alert"><span class="title"><i class="icon-remove-sign"></i> ERROR</span>';
    $this->_error_suffix = '</div>';

}

}
Sign up to request clarification or add additional context in comments.

Comments

0

Didn't you forget to actually use the $config file before running the validation?

$this->form_validation->set_rules($config);

4 Comments

Where should this be defined ? as this causes undifined variable "$config" when used in the controller constructor or function.
I had the impression this autoloaded the rules from the /application/config/form_validation.php codeigniter.com/user_guide/libraries/…
It does if you have created a config file and placed in the application/config/. Judging by your response, you have ;-) How about enabling the logs? You can check if your config file gets loaded indeed.
Thanks Robert, It seemed like the "form_validation.php" config was not getting included so it was just a case of loading it into the config manualy and then setting the config as the rule as you stated before in your first post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.