ZF-9419: Zend_Form_Decorator_ViewHelper::getValue ignores values set via Zend_Form_Element_Button::setValue

Description

Setting a value on a Zend_Form_Element_Button object using setValue does not result in a "value" name/value pair being included as an attribute in the rendered button tag. The getValue method in Zend_Form_Decorator_ViewHelper returns null when a Zend_Form_Element_Button element is detected.

As documented at http://www.w3schools.com/tags/tag_button.asp the button tag can has a "value" attribute that can be used to assign a value to a button independent of the label used.

This issue also occurs when attempting to set a "value" attribute using the setAttrib method of Zend_Form_Element_Button.

Comments

Assigned component

Thomas please could you reassign this to Zend_View as the button is rendered in Zend_View_Helper_FormButton::formButton(), i am not able to reassign Issues yet.

This is simply adding the attribute value to the rendered attributes. The Zend_Form_Element_Button has no method setValue() this method is inherited from Zend_Form_Element which means the Value is set, but gets not rendered.

The problem is on Zend_Form_Decorator_ViewHelper::getValue:


if (!$element instanceof Zend_Form_Element) {
    return null;
}

foreach ($this->_buttonTypes as $type) {
    if ($element instanceof $type) {
        if (stristr($type, 'button')) {
            $element->content = $element->getLabel();
            return null;
        }
        return $element->getLabel();
    }
}

return $element->getValue();

This means on button elements the label is the same as the value.

-> The ViewHelper decorator shouldn't handle differences of value/label. This should be done on view helper.

Closing as duplicate of ZF-5056, because that one contains a possible solution.