File indexing completed on 2024-12-22 05:37:13
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_View 0017 * @subpackage Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 0024 /** 0025 * Abstract class for extension 0026 */ 0027 // require_once 'Zend/View/Helper/FormElement.php'; 0028 0029 0030 /** 0031 * Helper to generate a "button" element 0032 * 0033 * @category Zend 0034 * @package Zend_View 0035 * @subpackage Helper 0036 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0037 * @license http://framework.zend.com/license/new-bsd New BSD License 0038 */ 0039 class Zend_View_Helper_FormButton extends Zend_View_Helper_FormElement 0040 { 0041 /** 0042 * Generates a 'button' element. 0043 * 0044 * @access public 0045 * 0046 * @param string|array $name If a string, the element name. If an 0047 * array, all other parameters are ignored, and the array elements 0048 * are extracted in place of added parameters. 0049 * 0050 * @param mixed $value The element value. 0051 * 0052 * @param array $attribs Attributes for the element tag. 0053 * 0054 * @return string The element XHTML. 0055 */ 0056 public function formButton($name, $value = null, $attribs = null) 0057 { 0058 $info = $this->_getInfo($name, $value, $attribs); 0059 extract($info); // name, id, value, attribs, options, listsep, disable, escape 0060 0061 // Get content 0062 $content = ''; 0063 if (isset($attribs['content'])) { 0064 $content = $attribs['content']; 0065 unset($attribs['content']); 0066 } else { 0067 $content = $value; 0068 } 0069 0070 // Ensure type is sane 0071 $type = 'button'; 0072 if (isset($attribs['type'])) { 0073 $attribs['type'] = strtolower($attribs['type']); 0074 if (in_array($attribs['type'], array('submit', 'reset', 'button'))) { 0075 $type = $attribs['type']; 0076 } 0077 unset($attribs['type']); 0078 } 0079 0080 // build the element 0081 if ($disable) { 0082 $attribs['disabled'] = 'disabled'; 0083 } 0084 0085 $content = ($escape) ? $this->view->escape($content) : $content; 0086 0087 $xhtml = '<button' 0088 . ' name="' . $this->view->escape($name) . '"' 0089 . ' id="' . $this->view->escape($id) . '"' 0090 . ' type="' . $type . '"'; 0091 0092 // add a value if one is given 0093 if (!empty($value)) { 0094 $xhtml .= ' value="' . $this->view->escape($value) . '"'; 0095 } 0096 0097 // add attributes and close start tag 0098 $xhtml .= $this->_htmlAttribs($attribs) . '>'; 0099 0100 // add content and end tag 0101 $xhtml .= $content . '</button>'; 0102 0103 return $xhtml; 0104 } 0105 }