import('form.FormElement');
class Checkbox extends FormElement {
- var $mChecked = false;
- var $mOptions = null;
- function __construct($name, $value = '') {
+ function __construct($name) {
$this->class = 'Checkbox';
$this->name = $name;
- $this->value = $value;
}
- function setChecked($value) { $this->mChecked = $value; }
- function isChecked() { return $this->mChecked; }
-
- function setData($value) { $this->mOptions = $value; }
- function getData() { return $this->mOptions; }
-
- function getHtml() {
+ function getHtml() {
+ if ($this->id == '') $this->id = $this->name;
- if ($this->id=="") $this->id = $this->name;
-
- $html = "\n\t<input type=\"checkbox\"";
- $html .= " name=\"$this->name\" id=\"$this->id\"";
+ $html = "\n\t<input type=\"checkbox\"";
+ $html.= " id=\"$this->id\" name=\"$this->name\"";
+
+ if ($this->value)
+ $html.= " checked=\"true\"";
if ($this->on_change!="")
$html .= " onchange=\"$this->on_change\"";
if ($this->style!="")
$html .= " style=\"$this->style\"";
- if ($this->mChecked || (($this->value == $this->mOptions) && ($this->value != null)))
- $html .= " checked=\"true\"";
+
if (!$this->isEnabled())
$html .= " disabled=\"disabled\"";
-
- $html .= " value=\"".htmlspecialchars($this->mOptions)."\"";
+
+ // Provide a value so that we pass "1" for set checkboxes on form submit.
+ // Otherwise the default is "on" string, which is not what we want.
+ $html .= " value=\"1\"";
$html .= "/>\n";