Skip to content

Bug: Validation rule with * gets incorrect values as dot array syntax #8128

Description

@kenjis

From #8079 (comment)

The name key is contacts.just.friends.*.name, not contacts.*.name.

    public function index(): string
    {
        // Extend the user guide case and add one more layer.
        $requestData = [
            'contacts' => [
                'name' => 'Joe Smith',
                'just' => [
                    'friends' => [
                        [
                            'name' => 'Fred Flinstone',
                        ],
                        [
                            'name' => 'Wilma',
                        ],
                    ],
                ],
            ],
        ];

        $this->validator = \Config\Services::validation();
        $this->validator->setRules([
            'contacts.*.name' => 'required|max_length[1]',
        ]);

        dd(
            $this->validator->run($requestData),
            $this->validator->getErrors(),
            $this->validator->getValidated()
        );
    }
$this->validator->run(...) boolean false
⧉⌕$this->validator->getErrors() array (2)
    ⇄contacts.just.friends.0.name => string (63) "The contacts.*.name field cannot exceed 1 characters in length."
    ⇄contacts.just.friends.1.name => string (63) "The contacts.*.name field cannot exceed 1 characters in length."
$this->validator->getValidated() array (0)
⧉ Called from .../app/Controllers/Home.php:34 [dd()]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions