Welcome Guest, Not a member yet? Register   Sign In
set_value with get
#1

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);
}
if(isset($_GET[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?

THX Big Grin ALOT
Reply
#2

Anybody?
Reply
#3

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 https://codeigniter.com/user_guide/libra...-than-post

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))
 
       $CI->form_validation->set_value($field$default)
 
       $CI->input->post($fieldFALSE);

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

Reply




Theme © iAndrew 2016 - Forum software by © MyBB