Welcome Guest, Not a member yet? Register   Sign In
Doubt about custom validation

(This post was last modified: 08-02-2023, 12:00 AM by pippuccio76.)

hi , i have a doubt about custom validation 

in controller the rule are :
and in validation class :
    public function my_validation_function(string $str,string $fields, array $data)
        $mymodel = new MyModel();
        $res = $mymodel->where('field_1',$data['field1'])

            return false;


            return true;

Why must I insert in controller the fields if in validation class there is every post variable ?

If your custom validation rule does not require parameters, you do not need to add any. See the "even" rule in the docs.
For your function/method, you should make the fields arg nullable by adding a ? like so:
PHP Code:
public function my_validation_function(string $str, ?string $fields, array $data) : bool 

With that, you should be able to use the $data array from the sent form/user input.

But if i must pass a variable to the function i must insert One , tought the variabile are not the variable that i Need. Because in Array $data there are are post variable.

You can not specify anything in the rules. See how "alpha" "alpha_numeric" are created
$data is an additional, not the main source of checks

Theme © iAndrew 2016 - Forum software by © MyBB