Welcome Guest, Not a member yet? Register   Sign In
Rule is_unique
#1

(This post was last modified: 01-03-2024, 04:08 AM by abmcr.)

I have this rule
Code:
$validation->setRule('email','Email', 'required|max_length[254]|valid_email|is_unique[users.email,id,{id}]');

When the validation run i get this error

LogicException
No validation rules for the placeholder: id
SYSTEMPATH/Validation/Validation.php at line 792

the users table has an id field.
I don't understrand where is the error

Thank you in advance

The placeholder don't recognize the id field value

This line work fine
Code:
$validation->setRule('email','Email', "required|max_length[254]|valid_email|is_unique[users.email,id,{$id}]");

Where $id is the id of the row
Reply
#2

You have to look in the manual for string-operations with variables :

https://www.php.net/manual/en/language.o...string.php
Reply
#3

This code is vulnerable. An attacker could substitute an arbitrary string for $id and execute the code.
Therefore, you should not write such code.

PHP Code:
$validation->setRule('email','Email'"required|max_length[254]|valid_email|is_unique[users.email,id,{$id}]"); 
Reply
#4

Quote:Since v4.3.5, you must set the validation rules for the placeholder field (the id field in the sample code above) for security.
https://codeigniter4.github.io/CodeIgnit...aceholders
Reply




Theme © iAndrew 2016 - Forum software by © MyBB