Welcome Guest, Not a member yet? Register   Sign In
Form Validation and the bahaviour when the field id NOT required
#1

[eluser]verisof[/eluser]
Hi, I'm not sure if that's exactly the bug, but this behaviour really surprised me, because I don't think it's logical.

This is the part of original CI_Form_validation class, function _execute:
Code:
// If the field is blank, but NOT required, no further tests are necessary
        $callback = FALSE;
        if ( ! in_array('required', $rules) AND is_null($postdata))
        {
            // Before we bail out, does the rule contain a callback?
            if (preg_match("/(callback_\w+)/", implode(' ', $rules), $match))
            {
                $callback = TRUE;
                $rules = (array('1' => $match[1]));
            }
            else
            {
                return;
            }
        }

The situation is: I have two fields (password and its control) but they are not required. If they are left empty, nothing happens, but if not, the control is launched (callback on the first field takes care of it).

My rules on those fields are:
1) password_new: 'trim|callback_new_password|xss_clean'
2) password_new2: 'trim|matches[password_new]|xss_clean'

Every case works except this one: when I fill the first field and I leave the second empty. That's because FV class doesn't check the "matches" part, because it thinks everything's fine because the field is empty and doesn't have "required" rule. But I don't care if it's empty, I need it to match the first field, every time!

Let me know what you think, if this behaviour is logical and I have just a different view. I think it should match other rules although it's empty and not required (at least some of them, like "matches").


Messages In This Thread
Form Validation and the bahaviour when the field id NOT required - by El Forum - 03-07-2009, 04:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB