src/Form/MessagesTrait.php
public function getMessages($elementName = null)
    {
        if (null === $elementName) {
            $messages = $this->messages;
            foreach ($this->iterator as $name => $element) {
                $messageSet = $element->getMessages();
                if (!is_array($messageSet) &&
                    !$messageSet instanceof Traversable ||
                    empty($messageSet)
                ) {
                    continue;
                }

                $messages[$name] = $messageSet;
            }

            return $messages;
        }

        if (!$this->has($elementName)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid element name "%s" provided to %s',
                $elementName,
                __METHOD__
            ));
        }

        $element = $this->get($elementName);
        return $element->getMessages();
    }
public function getMessages($elementName = null)
    {
        if (null === $elementName) {
            $messages = $this->messages;
            foreach ($this->iterator as $name => $element) {
                $messageSet = $element->getMessages();
                if (!is_array($messageSet) &&
                    !$messageSet instanceof Traversable ||
                    empty($messageSet)
                ) {
                    continue;
                }

                $messages[$name] = $messageSet;
            }

            return $messages;
        }

        if (!$this->has($elementName)) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid element name "%s" provided to %s',
                $elementName,
                __METHOD__
            ));
        }

        $element = $this->get($elementName);
        return $element->getMessages();
    }
public function getMessages ( $ elementName = null ) { if ( null === $ elementName ) { $ messages = $ this -> messages ; foreach ( $ this -> iterator as $ name => $ element ) { $ messageSet = $ element -> getMessages ( ) ; if ( ! is_array ( $ messageSet ) && ! $ messageSet instanceof Traversable || empty ( $ messageSet ) ) { continue ; } $ messages [ $ name ] = $ messageSet ; } return $ messages ; } if ( ! $ this -> has ( $ elementName ) ) { throw new Exception \ InvalidArgumentException ( sprintf ( 'Invalid element name "%s" provided to %s' , $ elementName , __METHOD__ ) ) ; } $ element = $ this -> get ( $ elementName ) ; return $ element -> getMessages ( ) ; }
Get validation error messages, if any

Returns a hash of element names/messages for all elements failing
validation, or, if $elementName is provided, messages for that element
only.

@param  null|string $elementName
@return array|Traversable
@throws Exception\InvalidArgumentException
Get validation error messages if any