CodeIgniter Forums

Full Version: set_value with get
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Since Codeigniter 3.xx or before the set_value method has changed.

I have this in MY_form_helper

function set_value($field = '', $default = ''){
if (FALSE === ($OBJ =& _get_validation_object()))
if (isset($_POST[$field]))
return form_prep($_POST[$field], $field);
return form_prep($_GET[$field], $field);
return $default;
return form_prep($OBJ->set_value($field, $default), $field);

In Codeigniter 3.xx it looks like this

function set_value($field, $default = '', $html_escape = TRUE)
$CI =& get_instance();

$value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
? $CI->form_validation->set_value($field, $default)
: $CI->input->post($field, FALSE);

isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;

can anybody help me rewrite it so it fixes my the get problem for my search input? and does the same as my prev code?

I would recommend passing your GET data to the form validation library with the set_data() method (or not using GET with form data). See

However, I believe the following might be the CI3 equivalent of your function:

PHP Code:
function set_value($field ''$default '')
   $CI =& get_instance();

   $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))

   isset($value) OR $value = ($CI->input->get($field) === null $default $CI->input->get($field));
   return ($html_escape) ? html_escape($value) : $value;