is there a rule to achieve the behaviour opposite to "match"...for example suppose you dont want a username to be the same as your password (for security reasons), hence you would need an validation error to be thrown if both values equal.
Is there a built in rule for that or would I have to write my own callback?
@mystiknrg You could create a custom rule or just do the following: In system/language/english (or as appropriate) /form_validation_lang.php add: $lang['not_matches']= "The %s field can not match the %s field."; In system/libraries/form_validation.php add: function not_matches($str, $field) { if ( ! isset($_POST[$field])) { return TRUE; } $field = $_POST[$field]; return ($str == $field) ? FALSE : TRUE; }
Why work with if .. else .. statements in check_exists_username? Something like this seems more logical to me:
[code]
function check_exists_username($username){ $query_str = "blah"; $result = blah; if ($result->num_rows() == 0) return true; return false;
}
[/code]
nalixl 1 month ago
@nalixl
$result = $this->db->query($query, $username);
return ($result->num_rows() > 0) ? true : false;
drago8701 1 week ago
Nicely done!
OldviSinger 3 months ago
'username_not_exists' - pahaha.
Alasdair I think I love you.
ldexterldesign 6 months ago
@ldexterldesign ok? I love you too?
Verbloten 6 months ago
is there a rule to achieve the behaviour opposite to "match"...for example suppose you dont want a username to be the same as your password (for security reasons), hence you would need an validation error to be thrown if both values equal.
Is there a built in rule for that or would I have to write my own callback?
THanks.
mystiknrg 1 year ago
Verbloten 1 year ago
@Verbloten
somewhere near function matches.
Then in your form rules simply say not_matches[username] for the password field
Verbloten 1 year ago
@Verbloten Oh wow..i didnt know it was that easy to extend the functionality of CI
Thanks alot for your quick response!
mystiknrg 1 year ago
Another excellent video. I learned a hell of a lot. Thanks very much!
Mike01010011 1 year ago
Comment removed
Mike01010011 1 year ago
Comment removed
Mike01010011 1 year ago
Pro
dannybarrx 2 years ago
Nice!!! waiting for parts 6 7 8 9 10!!!!!
dimpbizkit 2 years ago
Thanks, this was very helpful.
More please!!
static47 2 years ago
AWESOME tutorial. I'm new to CI so I found this super useful, so please add on part 6 and part 7. Very appreicate!!!
ibby0055 2 years ago