Custom Validation doesn't work? - 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: Custom Validation doesn't work? (/showthread.php?tid=72343) |
Custom Validation doesn't work? - sibiniv - 12-06-2018 Hi, I want to create custom validation rule but it not working. Config/Validation Code: public function test_validate(string $str, string &$error = null): bool App\Model Code: protected $validationRules = array( Result Quote:CodeIgniter\Validation\Exceptions\ValidationException For additional question, can someone give simpler example how to send parameters to the function? I don't get the 'require_with' example. https://codeigniter4.github.io/CodeIgniter4/libraries/validation.html?highlight=validation#allowing-parameter The new validation system is hard to understand compared to the previous callback system. RE: Custom Validation doesn't work? - donpwinston - 12-07-2018 The way I did it: Config/Validation.php PHP Code: /** Application/Validation/MyRules.php PHP Code: <?php namespace App\Validation; ..etc RE: Custom Validation doesn't work? - kilishan - 12-07-2018 Looks like you forgot to add it to the $ruleSets in Config/Validation. RE: Custom Validation doesn't work? - sibiniv - 12-09-2018 Thanks for the reply. So the function needs to be put in different file? I thought it was supposed to be placed below this line Code: //-------------------------------------------------------------------- RE: Custom Validation doesn't work? - donpwinston - 12-10-2018 You create a class whose member functions are your rules. Specify the class in the $ruleSets in Config/Validation.php. |