Repopulating the form fields using the Codeigniter form helper functions will not work when there is not validation assigned to a field. This post explains a solution that can be used to solve this issue.
The helper function set_value() is used for populating the values of the input boxes. The function rely on the CI form validation library for its purpose. The set_value() function looks for the value in the field object in the form validation library. But when there is no validation on a field the field object will not exists on the form validation class instance.
There are many ways to achieve this. One simple ways will be adding dummy validation on the field as given below.
$this->form_validation->set_rules(“field_name”,”Field Name”,”");
The second way will be overwriting the set_value() helper function after extending the CI form helper. Follow the below steps to solve it in this way.
- Create a file named MY_form_helper.php in helper folder. (application/helper)
- Write down the following code in it.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Form Value
*
* Grabs a value from the POST array for the specified field so you can
* re-populate an input field or textarea. If Form Validation
* is active it retrieves the info from the validation class
*
* @access public
* @param string
* @return mixed
*/
if ( ! function_exists('set_value'))
{
function set_value($field = '', $default = '')
{
$OBJ =& _get_validation_object();
if ($OBJ === TRUE && isset($OBJ->_field_data[$field]))
{
return form_prep($OBJ->set_value($field, $default));
}
else
{
if ( ! isset($_POST[$field]))
{
return $default;
}
return form_prep($_POST[$field]);
}
}
}
/* End of file MY_form_helper.php */
/* Location: ./application/helpers/MY_form_helper.php */
The third ways to solve the issue is by extending the CI form validation library. Please follow the below steps for extending the CI form validation library to solve the issue.
- Create a file named MY_Form_Validation libary
- Insert the following code in the file.

Thank you very much…its great. it saved my few hours.
Thank you for posting this. It was really helpful.