FormPassword.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 "password" 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_FormPassword extends Zend_View_Helper_FormElement
  35. {
  36. /**
  37. * Generates a 'password' 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 formPassword($name, $value = null, $attribs = null)
  52. {
  53. $info = $this->_getInfo($name, $value, $attribs);
  54. extract($info); // name, value, attribs, options, listsep, disable
  55. // is it disabled?
  56. $disabled = '';
  57. if ($disable) {
  58. // disabled
  59. $disabled = ' disabled="disabled"';
  60. }
  61. // determine the XHTML value
  62. $valueString = ' value=""';
  63. if (array_key_exists('renderPassword', $attribs)) {
  64. if ($attribs['renderPassword']) {
  65. $valueString = ' value="' . $this->view->escape($value) . '"';
  66. }
  67. unset($attribs['renderPassword']);
  68. }
  69. // XHTML or HTML end tag?
  70. $endTag = ' />';
  71. if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
  72. $endTag= '>';
  73. }
  74. // render the element
  75. $xhtml = '<input type="password"'
  76. . ' name="' . $this->view->escape($name) . '"'
  77. . ' id="' . $this->view->escape($id) . '"'
  78. . $valueString
  79. . $disabled
  80. . $this->_htmlAttribs($attribs)
  81. . $endTag;
  82. return $xhtml;
  83. }
  84. }