psf
 All Classes Functions Variables
combobox.php
1 <?php
2 
3 //Part of simple php framework (spf)
4 //
9 //
14 //
16 
17 if (!defined("PSF_ENTRY_POINT"))
18  die("Not a valid psf entry point");
19 
20 require_once (dirname(__FILE__) . "/element.php");
21 
23 {
24  public $Enabled = true;
25  public $Value = NULL;
26  public $Selected = false;
27  public $Text = NULL;
28 
29  public function __construct($_value = NULL, $_text = NULL, $_parent = NULL)
30  {
31  $this->Value = $_value;
32  $this->Text = $_text;
33  }
34 
35  public function ToHtml()
36  {
37  $_e = "<option";
38  if ($this->Value !== NULL)
39  $_e .= ' value="' . $this->Value . '"';
40  $_e .= ">";
41  $_e .= $this->Text . "</option>";
42  return $_e;
43  }
44 }
45 
46 class ComboBox extends HtmlElement
47 {
48  public $Multiple = false;
49  public $Enabled = true;
50  public $Name;
51  public $Autofocus = false;
52  public $Items = [];
53 
54  public function __construct($_name = NULL, $_parent = NULL)
55  {
56  $this->Name = $_name;
57  parent::__construct($_parent);
58  }
59 
60  public function AddValue($value, $text)
61  {
62  $this->Items[] = new ComboBoxItem($value, $text, $this);
63  }
64 
65  public function ToHtml()
66  {
67  $_e = "<select";
68  if ($this->Name !== NULL)
69  $_e .= " name=\"$this->Name\"";
70  if ($this->Style !== NULL)
71  $_e .= " style=\"" . $this->Style->ToCss() . "\"";
72  $_e .= ">\n";
73  foreach ($this->Items as $item)
74  $_e .= " " . $item->ToHtml() . "\n";
75  $_e .= "</select>";
76  return $_e;
77  }
78 }