Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
c0a782b
fix: add judge if validation fields have asterisk when user want to s…
ping-yee Aug 5, 2022
340c752
test: add test for validation error with asterisk field.
ping-yee Aug 5, 2022
9fc2b7a
cs: run cs-fix and static analysis
ping-yee Aug 5, 2022
4441fd1
feat: add public method to regenerate CSRF token
kenjis Jul 28, 2022
23d71d6
docs: add changelog and note
kenjis Aug 1, 2022
f1db96b
docs: the session_id acquisition method that is not described
naente Aug 6, 2022
4a6527a
fix: add a new param in processRules and getErrorMessage function.
ping-yee Aug 6, 2022
a8453e2
add: validation testing add label field
ping-yee Aug 6, 2022
3648faa
fix: cs-fixer
ping-yee Aug 6, 2022
4632602
Merge pull request from GHSA-6gch-wjxj-hc2w
MGatner Aug 6, 2022
cb71f73
Prep for 4.2.3 release
MGatner Aug 6, 2022
01dac95
Merge pull request #6349 from naente/develop
MGatner Aug 6, 2022
1be14e7
Update CHANGELOG.md
MGatner Aug 6, 2022
d77883e
Merge pull request #6353 from codeigniter4/release-4.2.3
MGatner Aug 7, 2022
9c0c695
Merge pull request #6354 from codeigniter4/develop
MGatner Aug 7, 2022
68ad806
docs: add @property to Session
kenjis Aug 7, 2022
55f3c23
docs: add Prefious and Next button
kenjis Aug 7, 2022
dc84e94
docs: add upgrade_423 in upgrading.rst
kenjis Aug 7, 2022
ab6aa3c
docs: remove space
kenjis Aug 7, 2022
a42651b
docs: add missing command prompt
kenjis Aug 7, 2022
b2aac31
docs: remove out-of-dated? description
kenjis Aug 7, 2022
d75dabd
docs: remove `--prefer-source`
kenjis Aug 7, 2022
fa50250
docs: improve description
kenjis Aug 7, 2022
d8fe98d
Merge pull request #6355 from kenjis/phpdocs-add-property-to-Session
samsonasik Aug 7, 2022
b667425
docs: remove unused directories in Structure
kenjis Aug 7, 2022
db1833a
docs: add missing tests directory
kenjis Aug 7, 2022
d0f0881
docs: remove `two`
kenjis Aug 7, 2022
23a18eb
Merge pull request #6356 from kenjis/fix-docs-upgrade_423.rst
kenjis Aug 7, 2022
776926f
chore: convert warning into error
kenjis Aug 8, 2022
b471880
docs: refactor sample code
kenjis Aug 8, 2022
09bcef4
chore: tweak options
kenjis Aug 8, 2022
416da02
fix: change the declaration of methods according to PSR-12.
ping-yee Aug 8, 2022
2da8ef8
Merge pull request #6357 from kenjis/fix-docs-installing_composer.rst
kenjis Aug 9, 2022
d4b0483
docs: fix @param type
kenjis Aug 9, 2022
6d51b2c
fix: Email class may not log an error when it fails to send
kenjis Aug 9, 2022
4511b3f
docs: improve explanation
kenjis Aug 9, 2022
cf662be
docs: add missing deprecation
kenjis Aug 9, 2022
1086703
Merge pull request #6359 from kenjis/make-sphinx-warning-to-error
kenjis Aug 9, 2022
4fdffaa
Merge pull request #6363 from kenjis/fix-docs-Forge-createTable
kenjis Aug 10, 2022
9204889
Merge pull request #6362 from kenjis/fix-email-logging
kenjis Aug 10, 2022
cb7b565
add : add a description to the changelog.
ping-yee Aug 11, 2022
7c12af8
docs: fix duplicate object description of ...
kenjis Aug 11, 2022
6d3a24b
Merge pull request #6369 from kenjis/fix-docs-sphinx-errors
kenjis Aug 11, 2022
34a1f5b
docs: update explanation for private methods
kenjis Aug 11, 2022
f9d93ce
docs: add about initController()
kenjis Aug 11, 2022
00c6596
Merge pull request #6368 from kenjis/fix-docs-controllers.rst
kenjis Aug 11, 2022
eb6e943
rebase: reslove conflicts
ping-yee Aug 12, 2022
fe010ba
fix: add judge if validation fields have asterisk when user want to s…
ping-yee Aug 5, 2022
dba4bee
test: add test for validation error with asterisk field.
ping-yee Aug 5, 2022
713d6bb
cs: run cs-fix and static analysis
ping-yee Aug 5, 2022
748bad7
fix: add a new param in processRules and getErrorMessage function.
ping-yee Aug 6, 2022
3320fdb
add: validation testing add label field
ping-yee Aug 6, 2022
c5d8cb2
fix: cs-fixer
ping-yee Aug 6, 2022
9bdf852
fix: change the declaration of methods according to PSR-12.
ping-yee Aug 8, 2022
3b9e662
Merge branch 'fix-validation-custom-error' of https://github.com/ping…
ping-yee Aug 12, 2022
fa442b4
add : add a description to the changelog in v4.2.4.
ping-yee Aug 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function run(?array $data = null, ?string $group = null, ?string $dbGroup
if (strpos($field, '*') !== false) {
// Process multiple fields
foreach ($values as $dotField => $value) {
$this->processRules($dotField, $setup['label'] ?? $field, $value, $rules, $data);
$this->processRules($dotField, $setup['label'] ?? $field, $value, $rules, $data, $field);
}
} else {
// Process single field
Expand Down Expand Up @@ -203,7 +203,7 @@ public function check($value, string $rule, array $errors = []): bool
* @param array|null $rules
* @param array $data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param array $data
* @param array $data The array of data to validate, with `DBGroup`.
* @param string|null $originalField The original asterisk field name like "foo.*.bar".

*/
protected function processRules(string $field, ?string $label, $value, $rules = null, ?array $data = null): bool
protected function processRules(string $field, ?string $label, $value, $rules = null, ?array $data = null, ?string $originalField = null): bool
{
if ($data === null) {
throw new InvalidArgumentException('You must supply the parameter: data.');
Expand Down Expand Up @@ -333,7 +333,8 @@ protected function processRules(string $field, ?string $label, $value, $rules =
$field,
$label,
$param,
(string) $value
(string) $value,
$originalField
);

return false;
Expand Down Expand Up @@ -706,13 +707,15 @@ public function setError(string $field, string $error): ValidationInterface
*
* @param string|null $value The value that caused the validation to fail.
*/
protected function getErrorMessage(string $rule, string $field, ?string $label = null, ?string $param = null, ?string $value = null): string
protected function getErrorMessage(string $rule, string $field, ?string $label = null, ?string $param = null, ?string $value = null, ?string $originalField = null): string
{
$param ??= '';

// Check if custom message has been defined by user
if (isset($this->customErrors[$field][$rule])) {
$message = lang($this->customErrors[$field][$rule]);
} elseif (null !== $originalField && isset($this->customErrors[$originalField][$rule])) {
$message = lang($this->customErrors[$originalField][$rule]);
} else {
// Try to grab a localized version of the message...
// lang() will return the rule name back if not found,
Expand Down
22 changes: 22 additions & 0 deletions tests/system/Validation/StrictRules/ValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ public function testRunGroupWithCustomErrorMessage(): void
], $this->validation->getErrors());
}

/**
* @see https://github.com/codeigniter4/CodeIgniter4/issues/6245
*/
public function testRunWithCustomErrorsAndAsteriskField(): void
{
$data = [
'foo' => [
['bar' => null],
['bar' => null],
],
];
$this->validation->setRules(
['foo.*.bar' => ['label' => 'foo bar', 'rules' => 'required']],
['foo.*.bar' => ['required' => 'Required']]
);
$this->validation->run($data);
$this->assertSame([
'foo.0.bar' => 'Required',
'foo.1.bar' => 'Required',
Comment on lines +379 to +380
Copy link
Member

@kenjis kenjis Aug 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you really okay with key like 'foo.0.bar'?
It seems a bit difficult to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as I known, validation service change the asterisk field to like 'foo.0.bar'.
As Issue #6245 show that.

], $this->validation->getErrors());
}

/**
* @dataProvider rulesSetupProvider
*
Expand Down