Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

checkbox-field.inc.php

Go to the documentation of this file.
00001 <?php
00008 class CheckboxField extends AbstractField
00009 {
00010     protected $label = '';
00011 
00012     public function __construct($name, Form &$parentForm, array $attribs = array())
00013     {
00014         //checkbox fields dont have titles, they have labels.
00015         if (!$attribs['title'])
00016             $attribs['title'] = '';
00017         
00018         //make our label.
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         //sweet home alabama
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 ?>

Generated on Fri Oct 27 12:26:39 2006 for BaseJumper by doxygen 1.3.9.1