I'm having a bit of an issue on understanding how to create my own custom callback form validation. I keep getting the message "callback_test_validation is not a valid rule"
What I've done:
- I created a directory outside of app: Modules\Rules, so my setup looks like:
app\
Modules\
|- Rules\
- My class (Modules\Rules\MyRules.php) is setup as such:
Code:
<?php namespace Modules\Rules;
class MyRules
{
public function test_validate(string $str, string &$error = null): bool
{
$error = 'test error';
return false;
}
}
- I've set the Config\Validation as such:
Code:
public $ruleSets = [
Rules::class,
FormatRules::class,
FileRules::class,
CreditCardRules::class,
\Modules\Rules\MyRules::class,
];
- In my controller, I'm trying to reference the callback validation as such:
Code:
$validation = \Config\Services::validation();
$rules = ['myname'=>['label'=>'My Name','rules'=>'callback_test_validation']];
$validation->setRules($rules);
Is this the right way to do it? Do I need to setup my folder structure differently?
Will [daytodata]