phpDocumentor form
[ class tree: form ] [ index: form ] [ all elements ]

Source for file Select.php

Documentation is available at Select.php

  1. <?
  2. /**
  3. * @package form
  4. * @filesource
  5. * @see HTML_FORM_COMPONENT_PATH.'/Select.php'
  6. * @copyright (c) http://Finn-Rasmussen.com
  7. * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
  8. * @author http://Finn-Rasmussen.com
  9. * @version 1.9
  10. * @since 21-oct-2005
  11. */
  12.  
  13. /**
  14. * The required files
  15. */
  16. require_once(HTML_PATH.'/Html.php');
  17. require_once(HTML_FORM_COMPONENT_PATH.'/Option.php');
  18.  
  19. /**
  20. * Generates a SELECT form element
  21. * <code>
  22. * Usage:
  23. * $select = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  24. * $select->add(new Option('$key,$value));
  25. * : :
  26. * print $select->getHtml();
  27. * OR
  28. * Select::start($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  29. * Option::display($key,$value);
  30. * : :
  31. * Select::end();
  32. * </code>
  33. * @package form
  34. */
  35.  
  36. class Select extends Html {
  37. var $name = ''; // The name of the element
  38. var $class = ''; // The css class
  39. var $onchange = ''; // On change event
  40. var $multiple = ''; // The multiple
  41. var $size = ''; // The size
  42. var $onclick = ''; // On click event
  43. var $title = ''; // The title
  44. var $tabindex = ''; // The tabindex
  45.  
  46.  
  47. /**
  48. * Constructor
  49. * @param String $name The name of the control
  50. * @param String $class The class name
  51. * @param String $onchange On Change Event name i.e. 'EMNE'
  52. * @param String $multiple The multiple attribute
  53. * @param String $size The size attribute
  54. * @param String $onclick On Click Event name i.e. 'EMNE'
  55. * @param String $title The tooltip
  56. * @param String $tabindex The tabindex
  57. */
  58. function Select($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
  59. $this->Html();
  60. $this->name = $name;
  61. $this->class = $class!=''?$class:CSS_SELECT_CLASS;
  62. $this->multiple = $multiple;
  63. $this->size = $size;
  64. $this->onclick = $onclick;
  65. $this->title = $title;
  66. $this->tabindex = $tabindex;
  67. if ($onchange!='') {
  68. // TODO : Is it realy this functionality I want ?
  69. $this->onchange = 'this.form['.$onchange.'].value=this.options[this.options.selectedIndex].value;';
  70. }
  71. }
  72.  
  73. /*
  74. * Returns the html for the start of the control
  75. * @return String the html
  76. */
  77. function getStart() {
  78. $html = '';
  79. $html .= '<select';
  80. $html .= $this->getAttribute('name');
  81. $html .= $this->getAttribute('class');
  82. $html .= $this->getAttribute('onchange');
  83. $html .= $this->getAttribute('multiple');
  84. $html .= $this->getAttribute('size');
  85. $html .= $this->getAttribute('onclick');
  86. $html .= $this->getAttribute('title');
  87. $html .= $this->getAttribute('tabindex');
  88. $html .= ">\r\n";
  89. return $html;
  90. }
  91.  
  92. /*
  93. * Returns the html for the end of the control
  94. * including the html for the added elements
  95. * @return String the complete html
  96. */
  97. function getEnd() {
  98. $html = '';
  99. $html .= "</select><br />\r\n";
  100. return $html;
  101. }
  102.  
  103. /*
  104. * Returns the html for the control
  105. * including the html for the added elements
  106. * @return String the complete html
  107. */
  108. function getHtml() {
  109. $html = $this->html;
  110. $html .= $this->getStart();
  111. $html .= $this->getElements(); // as html
  112. $html .= $this->getEnd();
  113. return $html;
  114. }
  115.  
  116. /**
  117. * Display start html
  118. * <code>
  119. * Usage:
  120. * Select::start($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  121. * </code>
  122. * @static
  123. * @param String $name The name of the control
  124. * @param String $class The class name
  125. * @param String $onchange On Change Event name i.e. 'EMNE'
  126. * @param String $multiple The multiple attribute
  127. * @param String $size The size attribute
  128. * @param String $onclick On Click Event name i.e. 'EMNE'
  129. * @param String $title The tooltip
  130. * @param String $tabindex The tabindex
  131. */
  132. function start($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
  133. $html = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  134. $html->addHtml($html->getStart());
  135. }
  136.  
  137. /**
  138. * Display end html
  139. * <code>
  140. * Usage:
  141. * Select::end();
  142. * </code>
  143. * @static
  144. */
  145. function end() {
  146. $html = new Html();
  147. $html->addHtml(Select::getEnd());
  148. }
  149.  
  150. /**
  151. * Display html
  152. * <code>
  153. * Usage:
  154. * Select::display($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  155. * </code>
  156. * @static
  157. * @param String $name The name of the control
  158. * @param String $class The class name
  159. * @param String $onchange On Change Event name i.e. 'EMNE'
  160. * @param String $multiple The multiple attribute
  161. * @param String $size The size attribute
  162. * @param String $onclick On Click Event name i.e. 'EMNE'
  163. * @param String $title The tooltip
  164. * @param String $tabindex The tabindex
  165. */
  166. function display($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
  167. $html = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
  168. $html->addHtml();
  169. }
  170. }
  171. ?>

Documentation generated on Thu, 22 Dec 2005 17:17:08 +0100 by phpDocumentor 1.3.0RC3