Welcome Guest, Not a member yet? Register   Sign In
Form verification callback function in Ci4
#1

(This post was last modified: 06-16-2020, 04:33 AM by jreklund.)

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?
Reply
#2

(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
I would change this world, but God doesn't give me the source.
Reply
#3

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?
Reply
#4

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB