Třída TCombo je komponentou ke třídě TForm a je potomkem třídy TCheckBox. TCombo generuje HTML kód pro zobrazení rozvinovací nabídky.
<?php
$a_zeme = array(
"1"=>"Česká republika",
"2"=>"Slovenská republika",
"3"=>"Jiná ...",
);
?>
<?php
class TCombo extends TCheckBox{
protected $submit = false;
protected $null_row;
protected $a_data=array();
public function __construct(){
$this->style = "TCombo";
}
public function SetSubmit($submit=true){
$this->submit = (boolean) $submit;
}
public function SetData($a_data){
$this->a_data = $a_data;
}
public function SetNullRow($null_row=true){
$this->null_row = (boolean) $null_row;
}
public function Render(){
if ($this->name == "") throw new exception("Name is empty.");
if (!IsSet($this->a_data)) throw new exception("I need for data.");
if ($this->TText_error) $code .= $this->TText_error->Render();
$code .= "<SELECT name="$this->name" ";
if ($this->style !="") $code .= "class="$this->style" ";
if ($this->submit) $code .= "onChange="javascript:submit();" ";
if ($this->alttext !="") $code .= "title="$this->alttext" ";
$code .= ">n";
if ($this->null_row){
$code .= "<OPTION ";
if ($this->value=="") $code .= "SELECTED ";
$code .= "VALUE=""> </OPTION>n";
}
foreach($this->a_data as $key => $value) {
if ($key == $this->value) {
$code .= "<OPTION SELECTED VALUE="$key">$value</OPTION>n";
}else $code .= "<OPTION VALUE="$key">$value</OPTION>n";
}
$code .= "</SELECT>n";
return $code;
}
}
?>