CodeIgniter Forums
Update data with (,) using is_unique is not work. Codeigniter v.4.4.3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Update data with (,) using is_unique is not work. Codeigniter v.4.4.3 (/showthread.php?tid=88973)



Update data with (,) using is_unique is not work. Codeigniter v.4.4.3 - adimancifi - 12-13-2023

Hi all.
I have problem with is_unique feature. I want to update data using is_unique feature but when I submit with the same data with comma it's make error "Title field must contain a unique value.". I'm using Codeigniter v.4.4.3

Here my code :

PHP Code:
$postTitle $postData['title'];

service('validation')->setRules([
    'title' => [
                'label'  => 'Title',
                'rules'  => [
                              'is_unique[t_post.title,title,{$postTitle}]'
                ]
  ]
]);

if ( 
service('validation')->withRequest(service('request'))->run() )
{
    // ready to update.

else 
{
    ddservice('validation')->getErrors() );



Current data title is : This is new post title

When I push : This is new post title
it's work properly.

When I push : This is new, post title       (with comma)
it's make error : Title field must contain a unique value.

So, I need help about that.


RE: Update data with (,) using is_unique is not work. Codeigniter v.4.4.3 - gabriel_fucci - 12-13-2023

probably '{$post Title}' is not recognized as the value of your variable, but a literal string '$postTitle'. In the documentation for the "is_unique" part it says this "Warning: If `$uuid` is a user input, be sure to validate the format of the value before using it. Otherwise, it is vulnerable.".

Try with concatenation to actually get the value of the variable like this: 'is_unique[t_post.title,title,' . $postTitle . ']'.