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

Source for file Option.php

Documentation is available at Option.php

  1. <?
  2. /**
  3. * @package form
  4. * @filesource
  5. * @see HTML_FORM_COMPONENT_PATH.'/Option.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.  
  18. /**
  19. * Generates an OPTION form element
  20. * <code>
  21. * Usage:
  22. * $option = new Option($text,$value,$selected,$title);
  23. * print $option->getHtml();
  24. * Or
  25. * Option::display($text,$value,$selected,$title);
  26. * </code>
  27. * @package form
  28. */
  29.  
  30. class Option extends Html {
  31. var $text = ''; // The text to show
  32. var $value = ''; // The value of the element
  33. var $selected = ''; // The selcted state of the option
  34. var $title = ''; // The title
  35.  
  36.  
  37. /**
  38. * Constructor
  39. * @param String $text The text to show
  40. * @param String $value The value, if any
  41. * @param String $selected The option is selected
  42. * @param String $title The tooltip
  43. */
  44. function Option($text,$value='',$selected='',$title='') {
  45. $this->Html();
  46. $this->text = $text;
  47. $this->value = $value;
  48. $this->selected = $selected;
  49. $this->title = $title;
  50. }
  51.  
  52. /**
  53. * Returns the html for the option control
  54. * @return String the complete html
  55. */
  56. function getHtml() {
  57. $html = $this->html;
  58. $html .= ' <option';
  59. $html .= $this->getAttribute('value');
  60. $html .= $this->getAttribute('selected');
  61. $html .= $this->getAttribute('title');
  62. $html .= '>';
  63. $html .= htmlspecialchars(stripslashes($this->text)); // Translate html special chars
  64. $html .= "</option>\r\n";
  65. return $html;
  66. }
  67.  
  68. /**
  69. * Display html
  70. * <code>
  71. * Usage:
  72. * Option::display($text,$value,$selected,$title);
  73. * </code>
  74. * @param String $text The text to show
  75. * @param String $value The value, if any
  76. * @param String $selected The option is selected
  77. * @param String $title The tooltip
  78. */
  79. function display($text,$value='',$selected='',$title='') {
  80. $html = new Option($text,$value,$selected,$title);
  81. $html->addHtml();
  82. }
  83. }
  84. ?>

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