codeigniter4 / CodeIgniter4

Open Source PHP Framework (originally from EllisLab)
https://codeigniter.com/
MIT License
5.4k stars 1.9k forks source link

Bug: Model validation rules is_unique fails on placeholder #7664

Closed erikkraijenoord closed 1 year ago

erikkraijenoord commented 1 year ago

PHP Version

8.1

CodeIgniter4 Version

4.3.6

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

MySQL 5.7.24

What happened?

Using the Myth Auth package to manage users, uppon saving their profile the validation inside the UserModel will check if the email is unique.

protected $validationRules = [
        'email'         => 'required|valid_email|is_unique[users.email,id,{id}]',
        'username'      => 'required|alpha_numeric_punct|min_length[3]|max_length[30]|is_unique[users.username,id,{id}]',
        'password_hash' => 'required',
];

Saving this has issues on the is_unique validation, error message given is: No validation rules for the placeholder: id

Steps to Reproduce

Basic composer installation with latest CodeIgniter4, and the use of MythAuth version 1.2.1.

  1. Modify a user basic steps like changing the username/emaiil for example.
  2. The UserModel will use $validationRules to process the request.

On step 2 it fails already.

Expected Output

Saving the user without any issues.

Anything else?

Before upgrading CodeIgniter4 we didn't have any issues, seems to me like a recent change in the way this works?

kenjis commented 1 year ago

To use Validation Placeholders securely, please remember to create a validation rule for the field you will use as a placeholder. https://codeigniter4.github.io/CodeIgniter4/installation/upgrade_435.html#validation-placeholders

kenjis commented 1 year ago

@erikkraijenoord If the error message is difficult to understand, please suggest a better message.