2
0

FormButton.php 3.1 KB

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