diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index 4c63b689a995..c43b7d997d88 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -440,6 +440,7 @@ public function testRulesSetup($rules, $expected, array $errors = []) $data = ['foo' => '']; $this->validation->setRules(['foo' => $rules], $errors); $this->validation->run($data); + $this->assertSame($expected, $this->validation->getError('foo')); } @@ -468,6 +469,10 @@ public function rulesSetupProvider(): Generator ['rules' => 'min_length[10]'], 'The foo field must be at least 10 characters in length.', ], + [ + ['rules' => ['min_length[10]']], + 'The foo field must be at least 10 characters in length.', + ], [ [ 'label' => 'Foo Bar', @@ -475,6 +480,13 @@ public function rulesSetupProvider(): Generator ], 'The Foo Bar field must be at least 10 characters in length.', ], + [ + [ + 'label' => 'Foo Bar', + 'rules' => ['min_length[10]'], + ], + 'The Foo Bar field must be at least 10 characters in length.', + ], [ [ 'label' => 'Foo Bar', diff --git a/user_guide_src/source/libraries/validation/006.php b/user_guide_src/source/libraries/validation/006.php index 24a771f70e31..5f7cbf645ab2 100644 --- a/user_guide_src/source/libraries/validation/006.php +++ b/user_guide_src/source/libraries/validation/006.php @@ -4,3 +4,8 @@ 'username' => 'required', 'password' => 'required|min_length[10]', ]); +// or +$validation->setRules([ + 'username' => 'required', + 'password' => ['required', 'min_length[10]'], +]); diff --git a/user_guide_src/source/libraries/validation/007.php b/user_guide_src/source/libraries/validation/007.php index b211d9c1cec5..cb12c5a61a79 100644 --- a/user_guide_src/source/libraries/validation/007.php +++ b/user_guide_src/source/libraries/validation/007.php @@ -4,3 +4,8 @@ 'username' => ['label' => 'Username', 'rules' => 'required'], 'password' => ['label' => 'Password', 'rules' => 'required|min_length[10]'], ]); +// or +$validation->setRules([ + 'username' => ['label' => 'Username', 'rules' => 'required'], + 'password' => ['label' => 'Password', 'rules' => ['required', 'min_length[10]']], +]);