FormImage.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 an "image" 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_FormImage extends Zend_View_Helper_FormElement
  35. {
  36. /**
  37. * Generates an 'image' 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 source ('src="..."') for the image.
  46. *
  47. * @param array $attribs Attributes for the element tag.
  48. *
  49. * @return string The element XHTML.
  50. */
  51. public function formImage($name, $value = null, $attribs = null)
  52. {
  53. $info = $this->_getInfo($name, $value, $attribs);
  54. extract($info); // name, value, attribs, options, listsep, disable
  55. // Determine if we should use the value or the src attribute
  56. if (isset($attribs['src'])) {
  57. $src = ' src="' . $this->view->escape($attribs['src']) . '"';
  58. unset($attribs['src']);
  59. } else {
  60. $src = ' src="' . $this->view->escape($value) . '"';
  61. unset($value);
  62. }
  63. // Do we have a value?
  64. if (isset($value) && !empty($value)) {
  65. $value = ' value="' . $this->view->escape($value) . '"';
  66. } else {
  67. $value = '';
  68. }
  69. // Disabled?
  70. $disabled = '';
  71. if ($disable) {
  72. $disabled = ' disabled="disabled"';
  73. }
  74. // XHTML or HTML end tag?
  75. $endTag = ' />';
  76. if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
  77. $endTag= '>';
  78. }
  79. // build the element
  80. $xhtml = '<input type="image"'
  81. . ' name="' . $this->view->escape($name) . '"'
  82. . ' id="' . $this->view->escape($id) . '"'
  83. . $src
  84. . $value
  85. . $disabled
  86. . $this->_htmlAttribs($attribs)
  87. . $endTag;
  88. return $xhtml;
  89. }
  90. }