Welcome Guest, Not a member yet? Register   Sign In
CI_Form_validation's set_value function
#1

[eluser]Unknown[/eluser]
I just realized that this function changed in CI 2.0, vis-a-vis 1.7.3.

Code:
function set_value($field = '', $default = '')
{
    if ( ! isset($this->_field_data[$field]))
    {
        return $default;
    }

    // If the data is an array output them one at a time.
    //     E.g: form_input('name[]', set_value('name[]');
    if (is_array($this->_field_data[$field]['postdata']))
    {
        return array_shift($this->_field_data[$field]['postdata']);
    }

    return $this->_field_data[$field]['postdata'];
}

The part where the function checks whether the value is an array and then performs an array_shift leads me to wonder if CI is trying to do too much. I usually use this function instead of the global set_value to obtain the POST data that is not form_prepped.

I can see this may make things easier for some coders who can repeatedly call set_value when repopulating form elements, but in other cases, whenever you call this function, your underlying data permanently changes! Also, I would prefer access to the submitted array rather than receiving popped values off it.

I know I can work around this either by accessing _field_data directly (ugly) or extending the class and the function. But I just want to point out that this change is a step in the wrong direction IMO...




Theme © iAndrew 2016 - Forum software by © MyBB