Details
Description
If user checks no options for a multiCheckbox element and a custom validation message is configured, the _getErrorMessages() function generates a warning and fails to return the custom message. The line that fails is " foreach ($value as $val)" because $value is set to null.
Made the following change to get around the problem: if (($this->isArray() || is_array($value)) && !empty($value)) {
protected function _getErrorMessages()
{
$translator = $this->getTranslator();
$messages = $this->getErrorMessages();
$value = $this->getValue();
foreach ($messages as $key => $message) {
if (null !== $translator) {
$message = $translator->translate($message);
}
if (($this->isArray() || is_array($value)) && !empty($value)) {
$aggregateMessages = array();
foreach ($value as $val) {
$aggregateMessages[] = str_replace('%value%', $val, $message);
}
$messages[$key] = $aggregateMessages;
} else {
$messages[$key] = str_replace('%value%', $value, $message);
}
}
return $messages;
}
I have also ran into this issue when trying to implement a custom error message. Are there any plans to fix this issue, or am I assigning the error message in an incorrect way?
$element = $this->createElement('MultiCheckbox', 'checkbox');
$element->addErrorMessage('Foo');