password.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. *
  39. * @param string $elementName (optional)Input field name attribute
  40. * @param string $elementLabel (optional)Input field label
  41. * @param mixed $attributes (optional)Either a typical HTML attribute string
  42. * or an associative array
  43. * @since 1.0
  44. * @access public
  45. * @return void
  46. * @throws
  47. */
  48. public function __construct($elementName=null, $elementLabel=null, $attributes=null)
  49. {
  50. $attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control';
  51. parent::__construct($elementName, $elementLabel, $attributes);
  52. $this->setType('password');
  53. }
  54. /**
  55. * Sets size of password element
  56. *
  57. * @param string $size Size of password field
  58. * @since 1.0
  59. * @access public
  60. * @return void
  61. */
  62. public function setSize($size)
  63. {
  64. $this->updateAttributes(array('size'=>$size));
  65. }
  66. /**
  67. * Sets maxlength of password element
  68. *
  69. * @param string $maxlength Maximum length of password field
  70. * @since 1.0
  71. * @access public
  72. * @return void
  73. */
  74. public function setMaxlength($maxlength)
  75. {
  76. $this->updateAttributes(array('maxlength'=>$maxlength));
  77. }
  78. /**
  79. * Returns the value of field without HTML tags (in this case, value is changed to a mask)
  80. *
  81. * @since 1.0
  82. * @access public
  83. * @return string
  84. * @throws
  85. */
  86. public function getFrozenHtml()
  87. {
  88. $value = $this->getValue();
  89. return ('' != $value? '**********': '&nbsp;') .
  90. $this->_getPersistantData();
  91. }
  92. }