Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Uniqueness with combination of a set of fields and User Defined message

Hi,

I'm using Unigueness validation with two fields and a custom message:

public function validation()
{
    $this->validate(new Uniqueness(array(
        'field' => array('email', 'name'),
        'message' => 'Some custom message'
    )));
}

But PHP raises a Notice for strstr function as follow:

**Notice:** Array to string conversion in /var/....

It seems there is bug in source uniqueness.zep line 212 :

link Source Here

/*
* Check if the developer has defined a custom message
*/
let message = this->getOption("message");
let replacePairs = [":field": field];
if empty message {
  if typeof field == "array" {
    let replacePairs = [":fields": join(", ", field)];
    let message = "Value of fields: :fields are already present in another record";
  } else {
    let message = "Value of field: ':field' is already present in another record";
  }
}

/*
* Append the message to the validator
*/
this->appendMessage(strtr(message, replacePairs), field, "Unique");

I think typeof field should be checked in first replacePairs declaration or use if/else condition to support that situation.

Thanks.



4.4k
Accepted
answer

I opened an issue 9 days ago in regards to this issue : https://github.com/phalcon/cphalcon/issues/10338

It looks like "dreamsxin" has fixed the issue and it is waiting to be merged into cphalcon

@Steven Greate and thanks

I opened an issue 9 days ago in regards to this issue : https://github.com/phalcon/cphalcon/issues/10338

It looks like "dreamsxin" has fixed the issue and it is waiting to be merged into cphalcon