protected function renderErrorMessages(Element $element)
    {
        $html = '';

        // if we have error messages, then also render those
        if ($element instanceof AbstractFormField && sizeof($element->getErrorMessages()) > 0) {
            // render the error as title?
            if ($this->errorFormat == self::RENDER_AS_ATTRIBUTE) {
                // if the element is a form field, add the errors in the title tag
                $element->setAttribute($this->errorTagOrAttr, implode("\n", $element->getErrorMessages()));
            } elseif ($this->errorFormat == self::RENDER_AS_TAG) {
                $tag = new Tag($this->errorTagOrAttr);
                $tag->setInnerHtml(implode('<br />' . PHP_EOL, $element->getErrorMessages()));
                $html .= $tag->render();
            }
        }

        return $html;
    }