/**
* The required files
*/
require_once(HTML_BASE_UTIL_PATH.'/Element.php');
require_once(HTML_BASE_UTIL_PATH.'/Htmlspecialchars.php');
/**
* Generates an OPTION form element
* <code>
* Usage:
* $option = new Option($text,$value,$selected,$title,$label);
* print $option->getHtml();
* Or
* Option::display($text,$value,$selected,$title,$label);
* </code>
* @package form
*/
class Option extends Element {
/**
* @var String $text The text to show to the user
*/
var $text = '';
/**
* @var String $selected The 'selected' text or ''
*/
var $selected = '';
/**
* @var String $label The label to show to the user
*/
var $label = '';
/**
* Constructor
* @param String $text The text to show
* @param String $value The value, if any
* @param String $selected The option is selected
* @param String $title The tooltip
* @param String $label The label
*/
function Option($text,$value='',$selected='',$title='',$label='') {
$name = ''; // Not supported
$class = '';
$tabindex = '';
$onclick = '';
$accesskey = '';
$this->Element($name,$value,$class,$title,$tabindex,$onclick,$accesskey);
$this->text = $text;
$this->selected = $selected;
if ($this->selected != '' && $this->selected != 'selected') {
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".'Unknown option attribute found for selected='.$this->selected.' accepted values are "" or "selected"');
}
$this->label = $label; // !=''?$label:$text
}
/**
* Returns the html for the option control
* @return String the complete html
*/
function getHtml() {
$html = $this->html;
$html .= "\t<option";
$html .= $this->getAttribute('value');
$html .= $this->getAttribute('selected');
$html .= $this->getAttribute('title');
$html .= $this->getAttribute('label');
$html .= '>';
$html .= Htmlspecialchars::encode($this->text); // Translate html special chars
$html .= "</option>\r\n";
return $html;
}
/**
* Display html
* <code>
* Usage:
* Option::display($text,$value,$selected,$title,$label);
* </code>
* @param String $text The text to show
* @param String $value The value, if any
* @param String $selected The option is selected
* @param String $title The tooltip
* @param String $label The label
*/
function display($text,$value='',$selected='',$title='',$label='') {
$html = new Option($text,$value,$selected,$title,$label);
$html->addHtml();
}
}
?>