hiddenselect.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4. * Hidden select pseudo-element
  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 Isaac Shepard <ishepard@bsiweb.com>
  17. * @copyright 2001-2009 The PHP Group
  18. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  19. * @version CVS: $Id: hiddenselect.php,v 1.7 2009/04/04 21:34:03 avb Exp $
  20. * @link http://pear.php.net/package/HTML_QuickForm
  21. */
  22. /**
  23. * Hidden select pseudo-element
  24. *
  25. * This class takes the same arguments as a select element, but instead
  26. * of creating a select ring it creates hidden elements for all values
  27. * already selected with setDefault or setConstant. This is useful if
  28. * you have a select ring that you don't want visible, but you need all
  29. * selected values to be passed.
  30. *
  31. * @category HTML
  32. * @package HTML_QuickForm
  33. * @author Isaac Shepard <ishepard@bsiweb.com>
  34. * @version Release: 3.2.11
  35. * @since 2.1
  36. */
  37. class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
  38. {
  39. // {{{ constructor
  40. /**
  41. * Class constructor
  42. *
  43. * @param string Select name attribute
  44. * @param mixed Label(s) for the select (not used)
  45. * @param mixed Data to be used to populate options
  46. * @param mixed Either a typical HTML attribute string or an associative array (not used)
  47. * @since 1.0
  48. * @access public
  49. * @return void
  50. */
  51. function HTML_QuickForm_hiddenselect($elementName=null, $elementLabel=null, $options=null, $attributes=null)
  52. {
  53. parent::__construct($elementName, $elementLabel, $attributes);
  54. $this->_persistantFreeze = true;
  55. $this->_type = 'hiddenselect';
  56. if (isset($options)) {
  57. $this->load($options);
  58. }
  59. } //end constructor
  60. // }}}
  61. // {{{ toHtml()
  62. /**
  63. * Returns the SELECT in HTML
  64. *
  65. * @since 1.0
  66. * @access public
  67. * @return string
  68. * @throws
  69. */
  70. function toHtml()
  71. {
  72. if (empty($this->_values)) {
  73. return '';
  74. }
  75. $tabs = $this->_getTabs();
  76. $name = $this->getPrivateName();
  77. $strHtml = '';
  78. foreach ($this->_values as $key => $val) {
  79. for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
  80. if ($val == $this->_options[$i]['attr']['value']) {
  81. $strHtml .= $tabs . '<input' . $this->_getAttrString(array(
  82. 'type' => 'hidden',
  83. 'name' => $name,
  84. 'value' => $val
  85. )) . " />\n" ;
  86. }
  87. }
  88. }
  89. return $strHtml;
  90. } //end func toHtml
  91. // }}}
  92. // {{{ accept()
  93. /**
  94. * This is essentially a hidden element and should be rendered as one
  95. */
  96. function accept(&$renderer)
  97. {
  98. $renderer->renderHidden($this);
  99. }
  100. // }}}
  101. } //end class HTML_QuickForm_hiddenselect
  102. ?>