Permalink
Browse files

Fix issue #539

Form validation language line keys were not prefixed. They are
now prefixed with 'form_validation_' in order to avoid collisions.
The old keys will still work if a prefixed match is not found, but
are DEPRECATED and will be removed in the next major version.

Also added upgrade notes and changelog entries for the new error
message format from PR #961.
  • Loading branch information...
1 parent 749f250 commit d4eec9f3638cc31dc8965f929b74a2b3b201b8b7 @narfbg narfbg committed Dec 14, 2012
@@ -26,32 +26,32 @@
*/
defined('BASEPATH') OR exit('No direct script access allowed');
-$lang['required'] = 'The {field} field is required.';
-$lang['isset'] = 'The {field} field must have a value.';
-$lang['valid_email'] = 'The {field} field must contain a valid email address.';
-$lang['valid_emails'] = 'The {field} field must contain all valid email addresses.';
-$lang['valid_url'] = 'The {field} field must contain a valid URL.';
-$lang['valid_ip'] = 'The {field} field must contain a valid IP.';
-$lang['min_length'] = 'The {field} field must be at least {param} characters in length.';
-$lang['max_length'] = 'The {field} field cannot exceed {param} characters in length.';
-$lang['exact_length'] = 'The {field} field must be exactly {param} characters in length.';
-$lang['alpha'] = 'The {field} field may only contain alphabetical characters.';
-$lang['alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.';
-$lang['alpha_dash'] = 'The {field} field may only contain alpha-numeric characters, underscores, and dashes.';
-$lang['numeric'] = 'The {field} field must contain only numbers.';
-$lang['is_numeric'] = 'The {field} field must contain only numeric characters.';
-$lang['integer'] = 'The {field} field must contain an integer.';
-$lang['regex_match'] = 'The {field} field is not in the correct format.';
-$lang['matches'] = 'The {field} field does not match the {param} field.';
-$lang['differs'] = 'The {field} field must differ from the {param} field.';
-$lang['is_unique'] = 'The {field} field must contain a unique value.';
-$lang['is_natural'] = 'The {field} field must only contain digits.';
-$lang['is_natural_no_zero'] = 'The {field} field must only contain digits and must be greater than zero.';
-$lang['decimal'] = 'The {field} field must contain a decimal number.';
-$lang['less_than'] = 'The {field} field must contain a number less than {param}.';
-$lang['less_than_equal_to'] = 'The {field} field must contain a number less than or equal to {param}.';
-$lang['greater_than'] = 'The {field} field must contain a number greater than {param}.';
-$lang['greater_than_equal_to'] = 'The {field} field must contain a number greater than or equal to {param}.';
+$lang['form_validation_required'] = 'The {field} field is required.';
+$lang['form_validation_isset'] = 'The {field} field must have a value.';
+$lang['form_validation_valid_email'] = 'The {field} field must contain a valid email address.';
+$lang['form_validation_valid_emails'] = 'The {field} field must contain all valid email addresses.';
+$lang['form_validation_valid_url'] = 'The {field} field must contain a valid URL.';
+$lang['form_validation_valid_ip'] = 'The {field} field must contain a valid IP.';
+$lang['form_validation_min_length'] = 'The {field} field must be at least {param} characters in length.';
+$lang['form_validation_max_length'] = 'The {field} field cannot exceed {param} characters in length.';
+$lang['form_validation_exact_length'] = 'The {field} field must be exactly {param} characters in length.';
+$lang['form_validation_alpha'] = 'The {field} field may only contain alphabetical characters.';
+$lang['form_validation_alpha_numeric'] = 'The {field} field may only contain alpha-numeric characters.';
+$lang['form_validation_alpha_dash'] = 'The {field} field may only contain alpha-numeric characters, underscores, and dashes.';
+$lang['form_validation_numeric'] = 'The {field} field must contain only numbers.';
+$lang['form_validation_is_numeric'] = 'The {field} field must contain only numeric characters.';
+$lang['form_validation_integer'] = 'The {field} field must contain an integer.';
+$lang['form_validation_regex_match'] = 'The {field} field is not in the correct format.';
+$lang['form_validation_matches'] = 'The {field} field does not match the {param} field.';
+$lang['form_validation_differs'] = 'The {field} field must differ from the {param} field.';
+$lang['form_validation_is_unique'] = 'The {field} field must contain a unique value.';
+$lang['form_validation_is_natural'] = 'The {field} field must only contain digits.';
+$lang['form_validation_is_natural_no_zero'] = 'The {field} field must only contain digits and must be greater than zero.';
+$lang['form_validation_decimal'] = 'The {field} field must contain a decimal number.';
+$lang['form_validation_less_than'] = 'The {field} field must contain a number less than {param}.';
+$lang['form_validation_less_than_equal_to'] = 'The {field} field must contain a number less than or equal to {param}.';
+$lang['form_validation_greater_than'] = 'The {field} field must contain a number greater than {param}.';
+$lang['form_validation_greater_than_equal_to'] = 'The {field} field must contain a number greater than or equal to {param}.';
/* End of file form_validation_lang.php */
/* Location: ./system/language/english/form_validation_lang.php */
@@ -609,7 +609,9 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
$line = $this->_error_messages[$type];
}
- elseif (FALSE === ($line = $this->CI->lang->line($type)))
+ elseif (FALSE === ($line = $this->CI->lang->line('form_validation_'.$type))
+ // DEPRECATED support for non-prefixed keys
+ && FALSE === ($line = $this->CI->lang->line($type, FALSE)))
{
$line = 'The field was not set';
}
@@ -749,7 +751,9 @@ protected function _execute($row, $rules, $postdata = NULL, $cycles = 0)
{
if ( ! isset($this->_error_messages[$rule]))
{
- if (FALSE === ($line = $this->CI->lang->line($rule)))
+ if (FALSE === ($line = $this->CI->lang->line('form_validation_'.$rule))
+ // DEPRECATED support for non-prefixed keys
+ && FALSE === ($line = $this->CI->lang->line($rule, FALSE)))
{
$line = 'Unable to access an error message corresponding to your field name.';
}
@@ -797,7 +801,9 @@ protected function _translate_fieldname($fieldname)
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($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;
}
@@ -807,7 +813,7 @@ protected function _translate_fieldname($fieldname)
}
// --------------------------------------------------------------------
-
+
/**
* Build an error message using the field and param.
*
@@ -73,7 +73,7 @@ Release Date: Not Released
- Added JS window name support to the :php:func:`anchor_popup()` function.
- Added support (auto-detection) for HTTP/1.1 response code 303 in :php:func:`redirect()`.
- Changed :php:func:`redirect()` to only choose the **refresh** method only on IIS servers, instead of all servers on Windows (when **auto** is used).
- - Changed :php:func:`anchor()`, :php:func:`anchor_popup()`, and :php:func:`redirect()` to support protocol-relative URLs, such as `redirect('//ellislab.com/codeigniter')`.
+ - Changed :php:func:`anchor()`, :php:func:`anchor_popup()`, and :php:func:`redirect()` to support protocol-relative URLs (e.g. *//ellislab.com/codeigniter*).
- Added XHTML Basic 1.1 doctype to :doc:`HTML Helper <helpers/html_helper>`.
- :doc:`Inflector Helper <helpers/inflector_helper>` changes include:
- Changed :php:func:`humanize()` to allow passing an input separator as its second parameter.
@@ -225,13 +225,15 @@ Release Date: Not Released
- Added method ``set_data()`` to set an alternative data array to be validated instead of the default ``$_POST``.
- Added method ``reset_validation()`` which resets internal validation variables in case of multiple validation routines.
- Added support for setting error delimiters in the config file via ``$config['error_prefix']`` and ``$config['error_suffix']``.
- - ``_execute()`` now considers input data to be invalid if a specified rule is not found.
+ - Internal method ``_execute()`` now considers input data to be invalid if a specified rule is not found.
- Removed method ``is_numeric()`` as it exists as a native PHP function and ``_execute()`` will find and use that (the **is_numeric** rule itself is deprecated since 1.6.1).
- Native PHP functions used as rules can now accept an additional parameter, other than the data itself.
- - Updated ``set_rules()`` to accept an array of rules as well as a string.
+ - Updated method ``set_rules()`` to accept an array of rules as well as a string.
- Fields that have empty rules set no longer run through validation (and therefore are not considered erroneous).
- Added rule **differs* to check if the value of a field differs from the value of another field.
- Added rule **valid_url**.
+ - Added support for named parameters in error messages.
+ - :doc:`Language <libraries/language>` line keys must now be prefixed with **form_validation_**.
- Added support for setting :doc:`Table <libraries/table>` class defaults in a config file.
- :doc:`Caching Library <libraries/caching>` changes include:
- Added Wincache driver.
@@ -138,7 +138,7 @@ If your application relies on IF EXISTS, you'll have to change its usage.
Step 11: Change usage of Email library with multiple emails
***********************************************************
-The :doc:`Email library <../libraries/email>` will automatically clear the
+The :doc:`Email Library <../libraries/email>` will automatically clear the
set parameters after successfully sending emails. To override this behaviour,
pass FALSE as the first parameter in the ``send()`` method:
@@ -149,13 +149,43 @@ pass FALSE as the first parameter in the ``send()`` method:
// Parameters won't be cleared
}
+***************************************************
+Step 12: Update your Form_validation language lines
+***************************************************
+
+Two improvements have been made to the :doc:`Form Validation Library
+<../libraries/form_validation>`'s :doc:`language <../libraries/language>`
+files and error messages format:
+
+ - :doc:`Language Library <../libraries/language>` line keys now must be
+ prefixed with **form_validation_** in order to avoid collisions::
+
+ // Old
+ $lang['rule'] = ...
+
+ // New
+ $lang['form_validation_rule'] = ...
+
+ - The error messages format has been changed to use named parameters, to
+ allow more flexibility than what `sprintf()` offers::
+
+ // Old
+ 'The %s field does not match the %s field.'
+
+ // New
+ 'The {field} field does not match the {param} field.'
+
+.. note:: The old formatting still works, but the non-prefixed line keys
+ are DEPRECATED and scheduled for removal in CodeIgniter 3.1+.
+ Therefore you're encouraged to update its usage sooner rather than
+ later.
****************************************************************
-Step 12: Remove usage of (previously) deprecated functionalities
+Step 13: Remove usage of (previously) deprecated functionalities
****************************************************************
-In addition to the ``$autoload['core']`` configuration setting, there's a number of other functionalities
-that have been removed in CodeIgniter 3.0.0:
+In addition to the ``$autoload['core']`` configuration setting, there's a
+number of other functionalities that have been removed in CodeIgniter 3.0.0:
The SHA1 library
================
Oops, something went wrong.

0 comments on commit d4eec9f

Please sign in to comment.