set_value() of form validation does not work if you do not place a corresponding form validation rules using the $this->form_validation->set_rules();
To be able to retain a form’s field value even if it’s not required, you need to set rules for it.
For me, i place a “trim” rule. in this way set_value will work and retain the value of a field in case a validation rule is not met.
in the controller:
$this->form_validation->set_rules('misc', 'Notes','trim');
In the form:
<input type="text" name="misc" value="<?=set_value('misc');?>"/>
Otherwise, if you have not placed a set_rule to misc, the value of the field misc will not be retained in case a validation rule is not met.


great post!!! exactly what I needed. No one else seemed to know this trick. Big up!
Thanks bambucea!. hope it helped you..
Cheers for the information.
Just tried this and found out passing the value null doesn’t work, but you can use an empty string instead of the trim validation.
I have not tried empty string.. thanks for the info.
I can confirm the empty string does work. Here is what I use to make sure all fields can be repopulated…
foreach ($_POST as $key => $value) $this->form_validation->set_rules($key, ”, ‘trim’);
Then further down I set the actual validation rules for individual fields
whoops, that was a modified version
foreach ($_POST as $key => $value) $this->form_validation->set_rules($key, ”, ”);
That’s what I get for pasting without looking
Thanks!