Welcome Guest, Not a member yet? Register   Sign In
Form Validation Translating Field Names Bug
#1

(This post was last modified: 04-13-2015, 08:57 AM by splodgeco.)

In version 3, the language library and form_validation class were changed to prefix validation errors with "form_validation_".  If I use my own language file for a filed name (as per the documentation), the language library logs an error that the language line could not be found (with the prefix of "form_validation_" added to it).

On closer inspection the _translate_fieldname function of the form_validation class checks if a translation is needed and then tries to load the language line with "form_validation_" prefixed and without.  The later indicating that this is deprecated and not logged as an error if not found.

Code:
protected function _translate_fieldname($fieldname)
{
    // Do we need to translate the field name?
    // We look for the prefix lang: to determine this
    if (sscanf($fieldname, 'lang:%s', $line) === 1)
    {
        // Were we able to translate the field name?  If not we use $line
        if (FALSE === ($fieldname = $this->CI->lang->line('form_validation_'.$line))
            // DEPRECATED support for non-prefixed keys
            && FALSE === ($fieldname = $this->CI->lang->line($line, FALSE)))
        {
            return $line;
        }
    }

    return $fieldname;
}

My assumption was that I was using my own custom human readable name from my own generated language files. I do not want to change all of my language files to include a prefix of "form_validation_" when they are not always used for that purpose. They are used as a human readable name given to fields or in other views I have created.

Is this a bug with the form_validation class as I suspect or an oversight in the documentation?  It feels like a bug as the function name suggests it is translating a field name and not a form validation error!
Reply


Messages In This Thread
Form Validation Translating Field Names Bug - by splodgeco - 04-13-2015, 08:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB