Create validation after field validation

Hello everyone. I need to create some validation rules that should be applied after the validations that are in the fields and before saving. For example, the sum of X fields cannot exceed 100 and others. This applies to both Create and Update. In which method should I implement them? And if anyone has a simple example, I would appreciate it. Thanks.
Solution:
$this->addError('data.TRATO1', 'XXXXXXX');
$this->halt();
$this->addError('data.TRATO1', 'XXXXXXX');
$this->halt();
...
Jump to solution
5 Replies
joao nivaldo
joao nivaldoOP2mo ago
I tried to use this but it didn't work. I think I did something wrong. I'll post the code I made and if possible correct me. Another thing is it possible to use this beforevalidate also in the Edit Page? protected function afterValidate(): void { $this->addError('TRATO1', 'XXXXXXX'); } I did it this way and it added the error to the bag correctly but did not stop the flow. I followed it and saved it normally.
joao nivaldo
joao nivaldoOP2mo ago
No description
Solution
LeandroFerreira
LeandroFerreira2mo ago
$this->addError('data.TRATO1', 'XXXXXXX');
$this->halt();
$this->addError('data.TRATO1', 'XXXXXXX');
$this->halt();
joao nivaldo
joao nivaldoOP2mo ago
My hero.... thks...

Did you find this page helpful?