00001 <?php
00008 class CheckboxField extends AbstractField
00009 {
00010 protected $label = '';
00011
00012 public function __construct($name, Form &$parentForm, array $attribs = array())
00013 {
00014
00015 if (!$attribs['title'])
00016 $attribs['title'] = '';
00017
00018
00019 if ($attribs['label'])
00020 {
00021 $this->label = $attribs['label'];
00022 unset($attribs['label']);
00023 }
00024 else
00025 $this->label = ucfirst(str_replace("_", " ", $name));
00026
00027
00028 parent::__construct($name, $parentForm, $attribs);
00029 }
00030
00034 function drawInput()
00035 {
00036 $attr = $this->extrasAsAttributes();
00037 echo "<input type=\"checkbox\" name=\"$this->name\" value=\"1\"",
00038 $this->value ? ' checked="checked" ' : '', "$attr/>";
00039
00040 if ($this->label)
00041 echo " <label for=\"$this->id\">$this->label</label>";
00042 }
00043
00044
00048 function validate()
00049 {
00050 $this->hasError = false;
00051 $this->value = isset($_POST[$this->name]) && $_POST[$this->name];
00052 }
00053 }
00054
00055 ?>