Skip to content

Commit 531bd77

Browse files
authored
Merge pull request #2539 from bivanbi/issue-2535-validation-documentation-lacks-reset-method
explanation of reset() method in section Working With Validation fixes #2535
2 parents e186885 + 5f5e5e8 commit 531bd77

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

user_guide_src/source/libraries/validation.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,26 @@ This method sets a rule group from the validation configuration to the validatio
383383

384384
$validation->setRuleGroup('signup');
385385

386+
Running Multiple Validations
387+
=======================================================
388+
389+
.. note:: ``run()`` method will not reset error state. Should a previous run fail,
390+
``run()`` will always return false and ``getErrors()`` will return
391+
all previous errors until explicitly reset.
392+
393+
If you intend to run multiple validations, for instance on different data sets or with different
394+
rules after one another, you might need to call ``$validation->reset()`` before each run to get rid of
395+
errors from previous run. Be aware that ``reset()`` will invalidate any data, rule or custom error
396+
you previously set, so ``setRules()``, ``setRuleGroup()`` etc. need to be repeated::
397+
398+
for ($userAccounts as $user) {
399+
$validation->reset();
400+
$validation->setRules($userAccountRules);
401+
if (!$validation->run($user)) {
402+
// handle validation errors
403+
}
404+
}
405+
386406
Working With Errors
387407
************************************************
388408

0 commit comments

Comments
 (0)