Welcome Guest, Not a member yet? Register   Sign In
CI4 Validation - how use/work with calleble functions
#1

(This post was last modified: 04-18-2019, 12:30 AM by Avega Soft.)

Hi everyone, I've read CI4-manual for validation library and not found example code how use/work with calleble or anonymous functions? When I use example code from CI3 - this code don't works     . May be anybody know how use calleble/ anonymous functions validation in CI4-version. Sorry for my English.    

My exaple rule for email code:

PHP Code:
'email' => [

 
                   'label'  => 'Email',
 
                   'rules'  => [

 
                       'required',
 
                       'valid_email',
 
                       [
 
                           'email_exist', function( $str )
 
                           {
 
                               return $this->checkExistsUserEmail$str );
 
                           }
 
                       ]
 
                   ],
 
                   'errors' => [

 
                       'email_exist' =>'Email not found'
 
                   ]
 
               
Reply
#2

See the news tutorial in the CodeIgniter 4 User Guide.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(04-18-2019, 04:05 AM)InsiteFX Wrote: See the news tutorial in the CodeIgniter 4 User Guide.


I can't find information about how to use calleble/anonymous functions in Tutorial .
Reply
#4

Agreed - the tutorial does not appear to deal with custom validation rules Sad

Not a full example, but https://codeigniter4.github.io/CodeIgnit...stom-rules
Reply
#5

Custom validation rules are done this way:

See https://forum.codeigniter.com/thread-72343.html
Simpler is always better
Reply
#6

(04-18-2019, 09:37 AM)ciadmin Wrote: Agreed - the tutorial does not appear to deal with custom validation rules Sad

Not a full example, but https://codeigniter4.github.io/CodeIgnit...stom-rules

If I am understand right, that anonymous function was removed from validation library? And when i need to use ONE anonymous function in my rules (in my case) - i must create special custom class for that, which i registered in Config/Validation.php ? I think in this case it's not right way - create class for one rule...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB