Welcome Guest, Not a member yet? Register   Sign In
Form Validation - Error Message for Anonoymous Function
#1

How do I set an error message for an anonymous function used to validate a field when using the form validation class?

Code:


PHP Code:
$this->form_validation->set_rules('referral-code''Referral Code', 
                                    
array( 'required',
                                           
'regex_match[/^[a-zA-Z0-9]+$/]',
                                           function(
$value){
                                              
// validation of code
                                           
}),
                                     array(
'required'=>'Please enter a valid referral code',
                                           
'regex_match'=>'Invalid referral code',
                                            
'?? what goes here ??' => 'The code did not pass the test'
                                           

                                  ); 
Reply
#2

You need to wrap it in another array and specify a message string name as the first parameter.
PHP Code:
$this->form_validation->set_rules(
        
'referral-code''Referral Code',
        array(
                
'required',
                
'regex_match[/^[a-zA-Z0-9]+$/]',
                array(
                        
'referral-code_callable',
                        function(
$str)
                        {
                                
// Check validity of $str and return TRUE or FALSE
                        
}
                )
        ),
        array(
                
'required'               =>'Please enter a valid referral code',
                
'regex_match'            =>'Invalid referral code',
                
'referral-code_callable' => 'The code did not pass the test'
        
)
); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB