Welcome Guest, Not a member yet? Register   Sign In
Form_Validation configuration not repopulating (maybe not even working?)
#1

[eluser]Unknown[/eluser]
I'm having a small issue with CI's integrated form_validation class. Right now I have my rules working by setting them with
Code:
$this->form_validation->set_rules('fieldname', 'humanname', 'rules')
I'm trying to clean my controller though so I tried to create my /config/form_validation.php file and did the values just like mentioned in the documentation - but when testing for failure the field does not repopulate.

I used the multi-tier set up, since later down the road I will have multiple forms. An example of my config was

Code:
$config = array(
'gameform' => array(
'field' => 'gamename', 'label' => 'Name', 'rules' => 'required'
)
)
);

Then added
Code:
$this->form_validation->run('gameform')
and nothing worked.

So this is a pretty beginner's problem, any ideas what would cause this to happen - or does re-population not work the same when using this set-up compared to setting the rules in the controller? Or can I not use the multi-tier set up with only one value.
#2

[eluser]InsiteFX[/eluser]
Without seeing your form code I would say that
you need to use set_value in your form code!

Read the User Guide on Form_Validation class and the form_helper.

InsiteFX
#3

[eluser]Unknown[/eluser]
I have set_value, and form_error set for all fields to be validated.

I have it all working flawlessly when I insert the values into my controller.
Code:
$this->form_validation->set_rules('field','name','rules'); // Pretend there are 20 of these.
if ( ! $this->form_validation_run() == FALSE )
{
$_POST['add_game'] = NULL;
$this->add();
}

Works, but when I remove the validation rules from my controller and set them into the configuration form_validation.php file, then it doesn't work.
#4

[eluser]InsiteFX[/eluser]
You should be using CI input below, now $__Post[]!

Code:
$data = $this->input->xss_clean($data);

Did you also load the form_helper?

Also your config should be like this:
Code:
$config = array(
'gameform' => array(
'field' => 'gamename', 'label' => 'Name', 'rules' => 'required'
// ) Remove one to many!
)
);

InsiteFX
#5

[eluser]Nisha S.[/eluser]
If there is no need for validating the fields then only load the form helper. If the form validation library is loaded then the set_value takes the value from the library object otherwise it refers to the $_POST array. You may get some more info from one of my post at http://www.betterhelpworld.com/codeignit...odeigniter




Theme © iAndrew 2016 - Forum software by © MyBB