• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.