We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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.



5.7k
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