password.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * HTML class for a password type field
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category HTML
  15. * @package HTML_QuickForm
  16. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  17. * @author Bertrand Mansion <bmansion@mamasam.com>
  18. * @copyright 2001-2009 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: password.php,v 1.8 2009/04/04 21:34:04 avb Exp $
  21. * @link http://pear.php.net/package/HTML_QuickForm
  22. */
  23. /**
  24. * HTML class for a password type field
  25. *
  26. * @category HTML
  27. * @package HTML_QuickForm
  28. * @author Adam Daniel <adaniel1@eesus.jnj.com>
  29. * @author Bertrand Mansion <bmansion@mamasam.com>
  30. * @version Release: 3.2.11
  31. * @since 1.0
  32. */
  33. class HTML_QuickForm_password extends HTML_QuickForm_text
  34. {
  35. // {{{ constructor
  36. /**
  37. * Class constructor
  38. * @param string $elementName (optional)Input field name attribute
  39. * @param string $elementLabel (optional)Input field label
  40. * @param mixed $attributes (optional)Either a typical HTML attribute string
  41. * or an associative array
  42. * @since 1.0
  43. * @access public
  44. * @throws
  45. */
  46. public function __construct($elementName=null, $elementLabel=null, $attributes=null)
  47. {
  48. $attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control';
  49. parent::__construct($elementName, $elementLabel, $attributes);
  50. $this->setType('password');
  51. }
  52. /**
  53. * Sets size of password element
  54. *
  55. * @param string $size Size of password field
  56. * @since 1.0
  57. * @access public
  58. * @return void
  59. */
  60. public function setSize($size)
  61. {
  62. $this->updateAttributes(array('size'=>$size));
  63. }
  64. /**
  65. * Sets maxlength of password element
  66. *
  67. * @param string $maxlength Maximum length of password field
  68. * @since 1.0
  69. * @access public
  70. * @return void
  71. */
  72. public function setMaxlength($maxlength)
  73. {
  74. $this->updateAttributes(array('maxlength'=>$maxlength));
  75. }
  76. /**
  77. * Returns the value of field without HTML tags (in this case, value is changed to a mask)
  78. *
  79. * @since 1.0
  80. * @access public
  81. * @return string
  82. * @throws
  83. */
  84. public function getFrozenHtml()
  85. {
  86. $value = $this->getValue();
  87. return ('' != $value? '**********': '&nbsp;') .
  88. $this->_getPersistantData();
  89. }
  90. }