HTML_Select
[ class tree: HTML_Select ] [ index: HTML_Select ] [ all elements ]

Source for file example.php

Documentation is available at example.php

  1. <?php
  2. /**
  3.  * Demo for HTML_Select
  4.  */
  5. //you do *not* need the following line!
  6.     dirname(__FILE__'/../'
  7.     . PATH_SEPARATOR . get_include_path()
  8. );
  9.  
  10. require_once 'HTML/Select.php';
  11.  
  12. //key is used as label, value as <option value="">.
  13. $colors = array(
  14.     'red'    => '#FF0000',
  15.     'green'  => '#00FF00',
  16.     'blue'   => '#0000FF',
  17.     'orange' => '#FF8000'
  18. );
  19. $years range(20002010);
  20.  
  21. //load key-value array
  22. $hs = new HTML_Select('color');
  23. $hs->load($colors);
  24.  
  25. //load array with values only
  26. //2004 is pre-selected
  27. $yearsel = new HTML_Select('year');
  28. $yearsel->loadValueArray($years2004);
  29.  
  30. echo <<<HTM
  31. <?xml version="1.0" encoding="utf-8"?>
  32. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  33.         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  34. <html xmlns="http://www.w3.org/1999/xhtml">
  35.  <head>
  36.   <title>HTML_Select demo</title>
  37.  </head>
  38.  <body>
  39.   <form method="get" action="#">
  40.    <p>
  41. <label for="color">Select a color:</label>
  42. HTM;
  43. echo $hs->toHtml();
  44.  
  45. echo <<<HTM
  46.    </p>
  47.    <p>
  48. <label for="year">Select a year:</label>
  49. HTM;
  50. echo $yearsel->toHtml();
  51. echo <<<HTM
  52.    </p>
  53.   </form>
  54.  </body>
  55. </html>
  56. HTM;
  57. ?>

Documentation generated on Mon, 11 Mar 2019 15:47:41 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.