Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added validation rule 'differs' #1871

Merged
merged 1 commit into from
Oct 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions system/language/english/form_validation_lang.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
$lang['integer'] = 'The %s field must contain an integer.'; $lang['integer'] = 'The %s field must contain an integer.';
$lang['regex_match'] = 'The %s field is not in the correct format.'; $lang['regex_match'] = 'The %s field is not in the correct format.';
$lang['matches'] = 'The %s field does not match the %s field.'; $lang['matches'] = 'The %s field does not match the %s field.';
$lang['differs'] = 'The %s field must differ from the %s field.';
$lang['is_unique'] = 'The %s field must contain a unique value.'; $lang['is_unique'] = 'The %s field must contain a unique value.';
$lang['is_natural'] = 'The %s field must only contain digits.'; $lang['is_natural'] = 'The %s field must only contain digits.';
$lang['is_natural_no_zero'] = 'The %s field must only contain digits and must be greater than zero.'; $lang['is_natural_no_zero'] = 'The %s field must only contain digits and must be greater than zero.';
Expand Down
13 changes: 13 additions & 0 deletions system/libraries/Form_validation.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -970,6 +970,19 @@ public function matches($str, $field)


// -------------------------------------------------------------------- // --------------------------------------------------------------------


/**
* Differs from another field
*
* @param string
* @param string field
* @return bool
*/
public function differs($str, $field)
{
return ! (isset($this->_field_data[$field]) && $this->_field_data[$field]['postdata'] === $str);
}

// --------------------------------------------------------------------
/** /**
* Is Unique * Is Unique
* *
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ Release Date: Not Released
- Native PHP functions used as rules can now accept an additional parameter, other than the data itself. - 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 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). - Fields that have empty rules set no longer run through validation (and therefore are not considered erroneous).
- Added new rule: ``differs``. It checks if the value of a field differs from the value of another field.
- Added support for setting :doc:`Table <libraries/table>` class defaults in a config file. - Added support for setting :doc:`Table <libraries/table>` class defaults in a config file.
- Added a Wincache driver to the :doc:`Caching Library <libraries/caching>`. - Added a Wincache driver to the :doc:`Caching Library <libraries/caching>`.
- Added a Redis driver to the :doc:`Caching Library <libraries/caching>`. - Added a Redis driver to the :doc:`Caching Library <libraries/caching>`.
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/libraries/form_validation.rst
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ Rule Parameter Description
========================= ========== ============================================================================================= ======================= ========================= ========== ============================================================================================= =======================
**required** No Returns FALSE if the form element is empty. **required** No Returns FALSE if the form element is empty.
**matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item] **matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item]
**differs** Yes Returns FALSE if the form element does not differ from the one in the parameter. differs[form_item]
**is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field] **is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field]
parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be
enabled in order to work. enabled in order to work.
Expand Down