Validation Class
Note: This page is an extension of the CodeIgniter User Guide page of the same name. Please read the CodeIgniter Validation Class section in addition to this page for complete information about this feature.
$this->validation->set_defaults()
This method allows you to set a default value for a field in the controller. In the controller, you just pass an array with fieldname => defval to $this->validation->set_defaults().
You must do this right after $this->validation->set_fields();
Your controller:
$fields = array(
'realname' => 'Real name'
);
$this->validation->set_fields($fields);
$defaults = array(
'realname' => 'defval'
);
$this->validation->set_defaults($defaults);
Note: This method will not prep your values so if you are loading ‘volatile’ data from the db, you have to prep it in the $defaults array.