|
1 <?php |
|
2 /** |
|
3 * Zend Framework |
|
4 * |
|
5 * LICENSE |
|
6 * |
|
7 * This source file is subject to the new BSD license that is bundled |
|
8 * with this package in the file LICENSE.txt. |
|
9 * It is also available through the world-wide-web at this URL: |
|
10 * http://framework.zend.com/license/new-bsd |
|
11 * If you did not receive a copy of the license and are unable to |
|
12 * obtain it through the world-wide-web, please send an email |
|
13 * to license@zend.com so we can send you a copy immediately. |
|
14 * |
|
15 * @category Zend |
|
16 * @package Zend_View |
|
17 * @subpackage Helper |
|
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
20 * @version $Id: FormButton.php 22290 2010-05-25 14:27:12Z matthew $ |
|
21 */ |
|
22 |
|
23 |
|
24 /** |
|
25 * Abstract class for extension |
|
26 */ |
|
27 require_once 'Zend/View/Helper/FormElement.php'; |
|
28 |
|
29 |
|
30 /** |
|
31 * Helper to generate a "button" element |
|
32 * |
|
33 * @category Zend |
|
34 * @package Zend_View |
|
35 * @subpackage Helper |
|
36 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
37 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
38 */ |
|
39 class Zend_View_Helper_FormButton extends Zend_View_Helper_FormElement |
|
40 { |
|
41 /** |
|
42 * Generates a 'button' element. |
|
43 * |
|
44 * @access public |
|
45 * |
|
46 * @param string|array $name If a string, the element name. If an |
|
47 * array, all other parameters are ignored, and the array elements |
|
48 * are extracted in place of added parameters. |
|
49 * |
|
50 * @param mixed $value The element value. |
|
51 * |
|
52 * @param array $attribs Attributes for the element tag. |
|
53 * |
|
54 * @return string The element XHTML. |
|
55 */ |
|
56 public function formButton($name, $value = null, $attribs = null) |
|
57 { |
|
58 $info = $this->_getInfo($name, $value, $attribs); |
|
59 extract($info); // name, id, value, attribs, options, listsep, disable, escape |
|
60 |
|
61 // Get content |
|
62 $content = ''; |
|
63 if (isset($attribs['content'])) { |
|
64 $content = $attribs['content']; |
|
65 unset($attribs['content']); |
|
66 } else { |
|
67 $content = $value; |
|
68 } |
|
69 |
|
70 // Ensure type is sane |
|
71 $type = 'button'; |
|
72 if (isset($attribs['type'])) { |
|
73 $attribs['type'] = strtolower($attribs['type']); |
|
74 if (in_array($attribs['type'], array('submit', 'reset', 'button'))) { |
|
75 $type = $attribs['type']; |
|
76 } |
|
77 unset($attribs['type']); |
|
78 } |
|
79 |
|
80 // build the element |
|
81 if ($disable) { |
|
82 $attribs['disabled'] = 'disabled'; |
|
83 } |
|
84 |
|
85 $content = ($escape) ? $this->view->escape($content) : $content; |
|
86 |
|
87 $xhtml = '<button' |
|
88 . ' name="' . $this->view->escape($name) . '"' |
|
89 . ' id="' . $this->view->escape($id) . '"' |
|
90 . ' type="' . $type . '"'; |
|
91 |
|
92 // add a value if one is given |
|
93 if (!empty($value)) { |
|
94 $xhtml .= ' value="' . $this->view->escape($value) . '"'; |
|
95 } |
|
96 |
|
97 // add attributes and close start tag |
|
98 $xhtml .= $this->_htmlAttribs($attribs) . '>'; |
|
99 |
|
100 // add content and end tag |
|
101 $xhtml .= $content . '</button>'; |
|
102 |
|
103 return $xhtml; |
|
104 } |
|
105 } |