![]() |
Allowing parameters in custom validation rules function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Allowing parameters in custom validation rules function (/showthread.php?tid=84992) |
Allowing parameters in custom validation rules function - objecttothis - 12-01-2022 According to the documentation (https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html#allowing-parameters) you can create a custom rule function that accepts parameters but no example of this rule being called is given, so it's unclear how it should be called. For example, if I have the following function: PHP Code: public function foo(string $bar, string $param, array $formData, string $customError): bool what does the validate call need to look like? I don't see how to add parameters to foo in the call below. PHP Code: if(!$this->validate(['bar' => 'required|foo'])) RE: Allowing parameters in custom validation rules function - objecttothis - 12-01-2022 Perhaps a clearer question is this: https://codeigniter4.github.io/userguide/libraries/validation.html#allowing-parameters The example function they give in that link is called required_with. What would it look like to call required_with as a rule in the validation? They don't give this in the example, so it seems abstract to me. RE: Allowing parameters in custom validation rules function - luckmoshy - 12-02-2022 do like this......... eg ![]() Code: public function validateUser(string $str, string $fields, array $data){ Code: $rules = [ |