Welcome Guest, Not a member yet? Register   Sign In
Update data with (,) using is_unique is not work. Codeigniter v.4.4.3
#1

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.
Reply
#2

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 . ']'.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB