The function below is for being sure the e-mail from form is unique, if it's already in use a message is showed. I want to change this message.
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->isUnique(['username']));
$rules->add($rules->isUnique(['email']));
return $rules;
}
I tried this way:
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->isUnique(['username']));
$rules->add($rules->isUnique(['email']),
['errorField' => 'email', 'message' => 'Este email já encontra-se em uso.']
);
return $rules;
}
It works but both messages are being showed, the default one and mine.
When using that style of adding unique rules, you'll have to pass the message to the
isUnique()
calls second argument, ieThat is because you are technically creating nested callables this way (
$rules->isUnique()
creates one, and$rules->add()
creates another one), and defining options in theadd()
call will cause them to be set in the outer callable, finally resulting in two messages being set, the one you've set for the outer callable, and the default one from the inner callable.Basically the above is the shorthand for
See also