ZF-3332: Fix HtmlTag Decorator to Accept Tag Content

Issue Type: Improvement Created: 2008-05-26T21:58:10.000+0000 Last Updated: 2012-05-08T07:52:30.000+0000 Status: Closed Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Brent Foust (bfoust) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: - ZF-10205



If the HtmlTag decorator allowed for a 'markup' option, then you could add HTML markup by passing a 'markup' option:

<pre class="highlight">
    $element = $this->getElement("password");
        'GeneralError' => 'HtmlTag'),
        array('tag' => 'div', 'class' => 'errors',
        'placement' => "prepend",
        'markup' => $this->getTranslator()->translate('login.form.loginfailed')));

HtmlTag would require the following simple changes (I've marked them with a trailing comment):

<pre class="highlight">
     * Render content wrapped in an HTML tag
     * @param  string $content
     * @return string
    public function render($content)
        $tag       = $this->getTag();
        $placement = $this->getPlacement();
        $noAttribs = $this->getOption('noAttribs');
        $openOnly  = $this->getOption('openOnly');
        $closeOnly = $this->getOption('closeOnly');
        $markup = $this->getOption('markup'); // html string to place after the opening tag -BF
        $this->removeOption('markup');         // remove, if supplied -BF
        $attribs = null;
        if (!$noAttribs) {
            $attribs = $this->getOptions();

        switch ($placement) {
            case self::APPEND:
                if ($closeOnly) {
                    return $content . $markup . $this->_getCloseTag($tag); // added ". $markup" -BF
                if ($openOnly) {
                    return $content . $this->_getOpenTag($tag, $attribs)
                    . $markup;          // added ". $markup" -BF
                return $content
                     . $this->_getOpenTag($tag, $attribs)
                     . $markup        // added ". $markup" -BF
                     . $this->_getCloseTag($tag);
            case self::PREPEND:
                if ($closeOnly) {
                    return  $markup . $this->_getCloseTag($tag) . $content; // added $markup -BF
                if ($openOnly) {
                    return $this->_getOpenTag($tag, $attribs) . $markup . $content; // added $markup -BF
                return $this->_getOpenTag($tag, $attribs)
                     . $markup           // added ". $markup" -BF
                     . $this->_getCloseTag($tag)
                     . $content;
                return (($openOnly || !$closeOnly) ? $this->_getOpenTag($tag, $attribs) : '')
                     . $content
                     . (($closeOnly || !$openOnly) ? $this->_getCloseTag($tag) : '');


Posted by Goran Juric (gog) on 2008-05-27T00:41:00.000+0000

Could you please create a patch from the file you are changing using the version from the trunk?

Posted by Matthew Weier O'Phinney (matthew) on 2008-05-27T05:50:59.000+0000

Scheduling for next minor release.

Posted by Pawel Przeradowski (squeaky) on 2008-08-10T04:59:19.000+0000

This would be a vaulable addition. As discussed on #zftalk this would allow to easily inject headers and other header related content into Zend_Form.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.