hiddenselect.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license, |
  9. // | that is bundled with this package in the file LICENSE, and is |
  10. // | available at through the world-wide-web at |
  11. // | http://www.php.net/license/2_02.txt. |
  12. // | If you did not receive a copy of the PHP license and are unable to |
  13. // | obtain it through the world-wide-web, please send a note to |
  14. // | license@php.net so we can mail you a copy immediately. |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
  17. // | Bertrand Mansion <bmansion@mamasam.com> |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: hiddenselect.php 9612 2006-10-20 11:56:44Z bmol $
  21. require_once('HTML/QuickForm/select.php');
  22. /**
  23. * This class takes the same arguments as a select element, but instead
  24. * of creating a select ring it creates hidden elements for all values
  25. * already selected with setDefault or setConstant. This is useful if
  26. * you have a select ring that you don't want visible, but you need all
  27. * selected values to be passed.
  28. *
  29. * @author Isaac Shepard <ishepard@bsiweb.com>
  30. *
  31. * @version 1.0
  32. * @since 2.1
  33. * @access public
  34. */
  35. class HTML_QuickForm_hiddenselect extends HTML_QuickForm_select
  36. {
  37. // {{{ constructor
  38. /**
  39. * Class constructor
  40. *
  41. * @param string Select name attribute
  42. * @param mixed Label(s) for the select (not used)
  43. * @param mixed Data to be used to populate options
  44. * @param mixed Either a typical HTML attribute string or an associative array (not used)
  45. * @since 1.0
  46. * @access public
  47. * @return void
  48. */
  49. function HTML_QuickForm_hiddenselect($elementName=null, $elementLabel=null, $options=null, $attributes=null)
  50. {
  51. HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
  52. $this->_persistantFreeze = true;
  53. $this->_type = 'hiddenselect';
  54. if (isset($options)) {
  55. $this->load($options);
  56. }
  57. } //end constructor
  58. // }}}
  59. // {{{ toHtml()
  60. /**
  61. * Returns the SELECT in HTML
  62. *
  63. * @since 1.0
  64. * @access public
  65. * @return string
  66. * @throws
  67. */
  68. function toHtml()
  69. {
  70. if (empty($this->_values)) {
  71. return '';
  72. }
  73. $tabs = $this->_getTabs();
  74. $name = $this->getPrivateName();
  75. $strHtml = '';
  76. foreach ($this->_values as $key => $val) {
  77. for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) {
  78. if ($val == $this->_options[$i]['attr']['value']) {
  79. $strHtml .= $tabs . '<input' . $this->_getAttrString(array(
  80. 'type' => 'hidden',
  81. 'name' => $name,
  82. 'value' => $val
  83. )) . " />\n" ;
  84. }
  85. }
  86. }
  87. return $strHtml;
  88. } //end func toHtml
  89. // }}}
  90. // {{{ accept()
  91. /**
  92. * This is essentially a hidden element and should be rendered as one
  93. */
  94. function accept(&$renderer)
  95. {
  96. $renderer->renderHidden($this);
  97. }
  98. // }}}
  99. } //end class HTML_QuickForm_hiddenselect
  100. ?>