hiddenselect.php 3.5 KB

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