CodeIgniter Forums
Form verification callback function in Ci4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Form verification callback function in Ci4 (/thread-76752.html)



Form verification callback function in Ci4 - mktek - 06-16-2020

Hello,

I have been using Ci3 for 3 years. I have developed many projects. I created a code pool for myself. Learning Ci3 is very easy. You can find many examples on the Internet. But Ci4 is not like that. I had a hard time learning. The documents are unfortunately not open enough. There is not enough sample code on the Internet. Obviously my enthusiasm was very broken.

For example, form validation in Ci3 is as follows:

Code:
$this->form_validation->set_rules('password', 'password', 'required|callback_check_database');

How can I do this with Ci4? Could you please explain it simply by writing code?


RE: Form verification callback function in Ci4 - Digital_Wolf - 06-16-2020

(06-16-2020, 04:32 AM)mktek Wrote: Hello,

I have been using Ci3 for 3 years. I have developed many projects. I created a code pool for myself. Learning Ci3 is very easy. You can find many examples on the Internet. But Ci4 is not like that. I had a hard time learning. The documents are unfortunately not open enough. There is not enough sample code on the Internet. Obviously my enthusiasm was very broken.

For example, form validation in Ci3 is as follows:

Code:
$this->form_validation->set_rules('password', 'password', 'required|callback_check_database');

How can I do this with Ci4? Could you please explain it simply by writing code?

Hello !
CI4 in this regard is practically no different from CI3.
PHP Code:
//  with using class:
$validation =  \Config\Services::validation(); 
 Read the user guide:
USER GUIDE


RE: Form verification callback function in Ci4 - mktek - 06-16-2020

Thanks for the answer Digital_Wolf. I have read the documents many times. I do standard form validation. but I failed to call the function. I could not find an example about this.

CI3 code:

Code:
$this->form_validation->set_rules('password', 'password', 'required|callback_check_database');


How can I call the "callback_check_database" function here with CI4?


RE: Form verification callback function in Ci4 - kilishan - 06-16-2020

Please see the section on Creating Custom Rules for examples. But basic steps are:

1. Create a new class to hold your custom rules
2. Let the system know about your new class in app/Config/Validation.php
3. Use the new method names as your rule names.