Added validation rule 'differs' #1871

Merged
merged 1 commit into from Oct 11, 2012

Projects

None yet

3 participants

@Dentxinho
Contributor

Added new validation rule 'differs'. It checks if the value of a field differs from the value of another field.

Contributor
ckdarby commented Oct 10, 2012

What exactly did you apply this to? I am having a hard time coming up with a case I'd use this in

Contributor

My exact use case:

Modifying organization > add a parent organization (select from a combo).
An organization can't be parent of yourself.
Even removing the current organization from the options of the combo, I needed to avoid inconsistences caused by form manipulation by the user.
So I created the rule so parent_id differs[id].

Another one:

<old password> <new password> <confirm new password>

-> new_password differs[old_password]
-> new_confirm matches[new_password}

Contributor
ckdarby commented Oct 10, 2012

Alright I can see the value of this. Update the chanelogs to reflect this added functionality.

Contributor

Done!

Contributor
ckdarby commented Oct 10, 2012

@narfbg Good sir please take a look when you get a chance

@narfbg narfbg commented on an outdated diff Oct 11, 2012
system/libraries/Form_validation.php
@@ -977,6 +977,25 @@ public function matches($str, $field)
// --------------------------------------------------------------------
/**
+ * Differs from another field
+ *
+ * @param string
+ * @param string field
+ * @return bool
+ */
+ public function differs($str, $field)
+ {
+ if ( ! isset($this->_field_data[$field]))
+ {
+ return TRUE;
+ }
+
+ return $str !== $this->_field_data[$field]['postdata'];
narfbg
narfbg Oct 11, 2012 Contributor

Needs to be in parentheses. Furthermore, the whole rule can be written like this:

return ! (isset($this->_field_data[$field]) && $this->_field_data[$field]['postdata'] === $str);
Contributor
narfbg commented Oct 11, 2012

You need to pull in changes from the repository, GitHub says that the PR can't be merged cause it's out of sync.

@Dentxinho Dentxinho New form_validation rule: 'differs'
Added new validation rule 'differs'. It checks if the value of a field differs from the value of another field.
f38564d
Contributor

@narfbg as expected =).

I've rebuilt the commits.

@narfbg narfbg merged commit 7d8b1db into bcit-ci:develop Oct 11, 2012

1 check failed

default The Travis build failed
Details
@narfbg narfbg added a commit that referenced this pull request Oct 11, 2012
@narfbg narfbg [ci skip] Minor changes following PR #1871 9ae82fa
Contributor

I'm sorry I ate that newline =x

Contributor
ckdarby commented Oct 11, 2012

@Dentxinho Congrats on your CodeIgniter pull being accepted and I hope to see more code from you in the future

Contributor

@ckdarby Thanks! You bet it :)

@nonchip nonchip pushed a commit to nonchip/CodeIgniter that referenced this pull request Jun 29, 2013
@narfbg narfbg [ci skip] Minor changes following PR #1871 274bc57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment