- <?
- /**
- * @package form
- * @filesource
- * @see HTML_FORM_COMPONENT_PATH.'/Select.php'
- * @copyright (c) http://Finn-Rasmussen.com
- * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
- * @author http://Finn-Rasmussen.com
- * @version 1.9
- * @since 21-oct-2005
- */
-
- /**
- * The required files
- */
- require_once(HTML_PATH.'/Html.php');
- require_once(HTML_FORM_COMPONENT_PATH.'/Option.php');
-
- /**
- * Generates a SELECT form element
- * <code>
- * Usage:
- * $select = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- * $select->add(new Option('$key,$value));
- * : :
- * print $select->getHtml();
- * OR
- * Select::start($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- * Option::display($key,$value);
- * : :
- * Select::end();
- * </code>
- * @package form
- */
-
- class Select extends Html {
- var $name = ''; // The name of the element
-
- var $class = ''; // The css class
-
- var $onchange = ''; // On change event
-
- var $multiple = ''; // The multiple
-
- var $size = ''; // The size
-
- var $onclick = ''; // On click event
-
- var $title = ''; // The title
-
- var $tabindex = ''; // The tabindex
-
-
-
- /**
- * Constructor
- * @param String $name The name of the control
- * @param String $class The class name
- * @param String $onchange On Change Event name i.e. 'EMNE'
- * @param String $multiple The multiple attribute
- * @param String $size The size attribute
- * @param String $onclick On Click Event name i.e. 'EMNE'
- * @param String $title The tooltip
- * @param String $tabindex The tabindex
- */
- function Select($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
- $this->Html();
- $this->name = $name;
- $this->class = $class!=''?$class:CSS_SELECT_CLASS;
- $this->multiple = $multiple;
- $this->size = $size;
- $this->onclick = $onclick;
- $this->title = $title;
- $this->tabindex = $tabindex;
- if ($onchange!='') {
- // TODO : Is it realy this functionality I want ?
- $this->onchange = 'this.form['.$onchange.'].value=this.options[this.options.selectedIndex].value;';
- }
- }
-
- /*
- * Returns the html for the start of the control
- * @return String the html
- */
- function getStart() {
- $html = '';
- $html .= '<select';
- $html .= $this->getAttribute('name');
- $html .= $this->getAttribute('class');
- $html .= $this->getAttribute('onchange');
- $html .= $this->getAttribute('multiple');
- $html .= $this->getAttribute('size');
- $html .= $this->getAttribute('onclick');
- $html .= $this->getAttribute('title');
- $html .= $this->getAttribute('tabindex');
- $html .= ">\r\n";
- return $html;
- }
-
- /*
- * Returns the html for the end of the control
- * including the html for the added elements
- * @return String the complete html
- */
- function getEnd() {
- $html = '';
- $html .= "</select><br />\r\n";
- return $html;
- }
-
- /*
- * Returns the html for the control
- * including the html for the added elements
- * @return String the complete html
- */
- function getHtml() {
- $html = $this->html;
- $html .= $this->getStart();
- $html .= $this->getElements(); // as html
- $html .= $this->getEnd();
- return $html;
- }
-
- /**
- * Display start html
- * <code>
- * Usage:
- * Select::start($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- * </code>
- * @static
- * @param String $name The name of the control
- * @param String $class The class name
- * @param String $onchange On Change Event name i.e. 'EMNE'
- * @param String $multiple The multiple attribute
- * @param String $size The size attribute
- * @param String $onclick On Click Event name i.e. 'EMNE'
- * @param String $title The tooltip
- * @param String $tabindex The tabindex
- */
- function start($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
- $html = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- $html->addHtml($html->getStart());
- }
-
- /**
- * Display end html
- * <code>
- * Usage:
- * Select::end();
- * </code>
- * @static
- */
- function end() {
- $html = new Html();
- $html->addHtml(Select::getEnd());
- }
-
- /**
- * Display html
- * <code>
- * Usage:
- * Select::display($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- * </code>
- * @static
- * @param String $name The name of the control
- * @param String $class The class name
- * @param String $onchange On Change Event name i.e. 'EMNE'
- * @param String $multiple The multiple attribute
- * @param String $size The size attribute
- * @param String $onclick On Click Event name i.e. 'EMNE'
- * @param String $title The tooltip
- * @param String $tabindex The tabindex
- */
- function display($name,$class='',$onchange='',$multiple='',$size='',$onclick='',$title='',$tabindex='') {
- $html = new Select($name,$class,$onchange,$multiple,$size,$onclick,$title,$tabindex);
- $html->addHtml();
- }
- }
- ?>