. */ class Staple_Form_CheckboxElement extends Staple_Form_Element { private $changed = false; private $checked = false; /** * * Override the default field value * @var unknown_type */ protected $value = 1; public function setChecked($bool = true) { $bool = (bool)$bool; $this->checked = $bool; return $this; } /** * Returns a boolean whether the checkbox is checked or not. * @return boolean */ public function isChecked() { if($this->checked === true) { return true; } else { return false; } } /** * Sets the starting value for the checkbox * @param boolean $val * @return Staple_Form_CheckboxElement */ public function setValue($val) { $this->setChecked($val); $this->changed = true; return $this; } /** * Returns the starting value for the checkbox * @return boolean */ public function getValue() { return (bool)$this->isChecked(); } /* (non-PHPdoc) * @see Staple_Form_Element::field() */ public function field() { $checked = ''; if($this->isChecked()) { $checked = ' checked'; } return ' getAttribString().'>'; } /* (non-PHPdoc) * @see Staple_Form_Element::label() */ public function label() { return ' '; } public function build() { $buf = ''; $view = FORMS_ROOT.'/fields/CheckboxElement.phtml'; if(file_exists($view)) { ob_start(); include $view; $buf = ob_get_contents(); ob_end_clean(); } else { $this->addClass('form_element'); $this->addClass('element_checkbox'); $classes = $this->getClassString(); $buf .= "