<?php
/**
 * Form button view helper for <input type='button' /> tag. This is missed
 * input type in the Zend_Form component.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * Form button view helper for <input type='button' /> tag. This is missed
 * input type in the Zend_Form component.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class HomeWebApp_View_Helper_FormButtonType extends Zend_View_Helper_FormElement
{
    /**
     * Main helper function
     * @param string $name button name - html name parameter
     * @param string $value button value - html value parameter
     * @param array $attribs other attributes, key=>value array, it will be used as
     * input xhtml parameters
     */
    public function formButtonType($name, $value = null, $attribs = null)
    {
        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

        // check if disabled
        $disabled = '';
        if ($disable) {
            $disabled = ' disabled="disabled"';
        }

        // XHTML or HTML end tag?
        $endTag = ' />';
        if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
            $endTag= '>';
        }

        //value is 'content' attribute
        if (isset($attribs['content'])) {
            $value = $attribs['content'];
            unset($attribs['content']);
        }
        
        // ignore disable/enable, always show the button.
        $xhtml = '<input type="button"'
            . ' name="' . $this->view->escape($name) . '"'
            . ' id="' . $this->view->escape($id) . '"'
            . ' value="' . $this->view->escape($value) . '"'
            . $disabled
            . $this->_htmlAttribs($attribs)
            . $endTag;

        return $xhtml;
    }
}
