Skip to content

Bug: Validation placeholder not being replaced #2817

Closed
@nControl88

Description

@nControl88

Describe the bug
When using validation placeholders in a model and validating data, the placeholder is not being replaced with the actual data. The validation therefore returns false.

CodeIgniter 4 version
4.0.2

Expected behavior, and steps to reproduce if appropriate
Using the myth-auth package and the GroupModel. Validation rules are defined in the model as:

protected $validationRules = [
	'name' => 'required|max_length[255]|is_unique[auth_groups.name,name,{name}]',
	'description' => 'max_length[255]',
];

When trying to update a group in the controller using an already existing name in the database:

$groupModel = new GroupModel();

if (! $this->validate($rules = $groupModel->getValidationRules())) {
	return redirect()->back()->withInput()->with('errors', $groupModel->errors());
}

The validation returns false. Looking at the DB (MySQL) query ran it can be seen why:
SELECT 1 FROM `auth_groups` WHERE `name` = 'admin' AND `name` != '{name}' LIMIT 1

A manual replacement of {name} with the actual value resolves the issue.

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