From 277451a42c8fac9c4dfc8f4d4c54e0e7a19e0dc1 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Sat, 20 Sep 2008 03:42:20 +0000 Subject: Added the ability to set translatable field names --- user_guide/libraries/form_validation.html | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'user_guide/libraries') diff --git a/user_guide/libraries/form_validation.html b/user_guide/libraries/form_validation.html index cd5bc2a81..f7fede674 100644 --- a/user_guide/libraries/form_validation.html +++ b/user_guide/libraries/form_validation.html @@ -77,6 +77,7 @@ have left the old class in the library so applications currently using it will n
  • Callbacks
  • Setting Error Messages
  • Changing the Error Delimiters
  • +
  • Translating Field Names
  • Showing Errors Individually
  • Saving Sets of Validation Rules to a Config File
  • Using Arrays as Field Names
  • @@ -296,7 +297,7 @@ at the same time. To set validation rules you will use the set_rules()
  • The field name - the exact name you've given the form field.
  • -
  • A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username".
  • +
  • A "human" name for this field, which will be inserted into the error message. For example, if your field is named "user" you might give it a human name of "Username". Note: If you would like the field name to be stored in a language file, please see Translating Field Names.
  • The validation rules for this form field.
  • @@ -590,6 +591,28 @@ it is assumed that the data is your newly processed form data.

    + +

    Translating Field Names

    + +

    If you would like to store the "human" name you passed to the set_rules() function in a language file, and therefore make the name able to be translated, here's how:

    + +

    First, prefix your "human" name with lang:, as in this example:

    + + +$this->form_validation->set_rules('first_name', 'lang:first_name', 'required');
    +
    + +

    Then, store the name in one of your language file arrays (without the prefix):

    + +$lang['first_name'] = 'First Name'; + +

    Note: If you store your array item in a language file that is not loaded automatically by CI, you'll need to remember to load it in your controller using:

    + +$this->lang->load('file_name'); + +

    See the Language Class page for more info regarding language files.

    + +

    Changing the Error Delimiters

    -- cgit v1.2.3-24-g4f1b