Třída TButton je komponentou ke třídě TForm a je potomkem třídy TText. TButton generuje HTML kód pro zobrazení funkčního tlačítka ve formuláři.
<?php
class TButton extends TText {
protected $submit = false;
protected $reset = false;
protected $onclick;
protected $alttext;
protected $accesskey;
public function __construct(){
$this->style = "TButton";
}
public function SetSubmit($submit=true){
$this->submit = (boolean) $submit;
}
public function SetReset($reset=true){
$this->reset = (boolean) $reset;
}
public function SetAltText($alttext){
$alttext = trim($alttext);
$this->alttext = $alttext;
}
public function SetAccessKey($accesskey){
$accesskey = strtoupper(trim($accesskey));
$this->accesskey = $accesskey{0};
}
public function SetOnClick($onclick_code){
$this->onclick = $onclick_code;
}
public function Render(){
if ($this->name == "") throw new exception("Name is empty.");
$type = "button";
if ($this->submit) $type = "submit";
if ($this->reset) $type = "reset";
$code = "<INPUT type="$type" name="$this->name" value="$this->value" ";
if ($this->alttext !="") $code .= "title="$this->alttext" ";
if ($this->style !="") $code .= "class="$this->style" ";
if ($this->onclick !="") $code .= "onclick="$this->onclick" ";
if ($this->accesskey !="") $code .= "accesskey="$this->accesskey" ";
$code .= ">";
return $code;
}
}
?>