~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/View/Helper/FormButton.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 */
 
21
 
 
22
 
 
23
/**
 
24
 * Abstract class for extension
 
25
 */
 
26
require_once 'Zend/View/Helper/FormElement.php';
 
27
 
 
28
 
 
29
/**
 
30
 * Helper to generate a "button" element
 
31
 *
 
32
 * @category   Zend
 
33
 * @package    Zend_View
 
34
 * @subpackage Helper
 
35
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
36
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
37
 */
 
38
class Zend_View_Helper_FormButton extends Zend_View_Helper_FormElement
 
39
{
 
40
    /**
 
41
     * Generates a 'button' element.
 
42
     *
 
43
     * @access public
 
44
     *
 
45
     * @param string|array $name If a string, the element name.  If an
 
46
     * array, all other parameters are ignored, and the array elements
 
47
     * are extracted in place of added parameters.
 
48
     *
 
49
     * @param mixed $value The element value.
 
50
     *
 
51
     * @param array $attribs Attributes for the element tag.
 
52
     *
 
53
     * @return string The element XHTML.
 
54
     */
 
55
    public function formButton($name, $value = null, $attribs = null)
 
56
    {
 
57
        $info    = $this->_getInfo($name, $value, $attribs);
 
58
        extract($info); // name, id, value, attribs, options, listsep, disable
 
59
 
 
60
        // Get content
 
61
        $content = '';
 
62
        if (isset($attribs['content'])) {
 
63
            $content = $attribs['content'];
 
64
            unset($attribs['content']);
 
65
        } else {
 
66
            $content = $value;
 
67
        }
 
68
 
 
69
        // Ensure type is sane
 
70
        $type = 'button';
 
71
        if (isset($attribs['type'])) {
 
72
            $attribs['type'] = strtolower($attribs['type']);
 
73
            if (in_array($attribs['type'], array('submit', 'reset', 'button'))) {
 
74
                $type = $attribs['type'];
 
75
            }
 
76
            unset($attribs['type']);
 
77
        }
 
78
 
 
79
        // build the element
 
80
        if ($disable) {
 
81
            $attribs['disabled'] = 'disabled';
 
82
        }
 
83
 
 
84
        $content = ($escape) ? $this->view->escape($content) : $content;
 
85
 
 
86
        $xhtml = '<button'
 
87
                . ' name="' . $this->view->escape($name) . '"'
 
88
                . ' id="' . $this->view->escape($id) . '"'
 
89
                . ' type="' . $type . '"';
 
90
 
 
91
        // add a value if one is given
 
92
        if (!empty($value)) {
 
93
            $xhtml .= ' value="' . $this->view->escape($value) . '"';
 
94
        }
 
95
 
 
96
        // add attributes and close start tag
 
97
        $xhtml .= $this->_htmlAttribs($attribs) . '>';
 
98
 
 
99
        // add content and end tag
 
100
        $xhtml .= $content . '</button>';
 
101
 
 
102
        return $xhtml;
 
103
    }
 
104
}