Search code examples
phpcodeignitercodeigniter-2

Use language files in form_validation of Codeigniter


I´m validating a form with the codeigniter form validation class and an own form_validation file in the configuration. Additionally I´m using the language class for translation. That works perfect in view and controller but I need to get the translation also in the config/form_validation.php.

Has anybody an idea how I can do that?

Excerpt of the config/form_validation.php

$config = array(

/**
 * Login form
 */
'auth/login' => array(
    array(
        'field' => 'email',
        'label' => 'E-Mail address', <--- HERE I´D LIKE TO USE THE TRANSLATIONS
        'rules' => 'trim|required|xss_clean|valid_email'
    ),
    array(
        'field' => 'password',
        'label' => 'Password',
        'rules' => 'trim|required|xss_clean'
    )
),
.....

Thanks for your ideas, best Michael


Solution

  • You can use the 'lang' prefix like..

    'auth/login' => array(
      array(
        'field' => 'email',
        'label' => 'lang:email_address_label',
        'rules' => 'trim|required|xss_clean|valid_email'
      )