Welcome Guest, Not a member yet? Register   Sign In
Form validation callables combined with "required"
#1

(This post was last modified: 02-06-2016, 09:12 AM by skunkbad.)

When I'm using the form validation Callables feature, if combined with Cascaded rules ,and specifically leaving out "required", my callable function is still run and returning FALSE, causing the form validation to return FALSE when run .

In the docs the callables feature is specifically shown with "required":


PHP Code:
$this->form_validation->set_rules(
 
       'username''Username',
       array(
               'required'// <- even if you leave this out, the callable function may return FALSE.
               function($value)
               {
                       // Check $value
               }
       )
); 

In my own validation rules, I am doing this to get around this issue:


PHP Code:
[
    'field' => 'passwd',
    'label' => 'PASSWORD',
    'rules' => [
        'trim',
        
            '_check_password_strength'
            function( $str ) use ( $CI 
            {
                return empty( $str )
                    TRUE
                    
$CI->validation_callables->_check_password_strength$str );
            }
        ]
    ]
], 


But since the docs show that the callables feature is used in conjunction with "required", I am wondering if I am missing something? Ideally, if I leave out "required", and if there is no value to validate, the callable function would not run and cause validation to fail. That desired behavior is just the way form validation behaves when these callable functions are not used.
Reply


Messages In This Thread
Form validation callables combined with "required" - by skunkbad - 02-06-2016, 09:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB