From 93977e579cca9a9d0df28099e1fb7596bcc1c825 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 15 Dec 2008 09:22:32 +0000 Subject: Refresh of Forge r168 from vendor/forge/modified --- modules/forge/libraries/Form_Checkbox.php | 83 +++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 modules/forge/libraries/Form_Checkbox.php (limited to 'modules/forge/libraries/Form_Checkbox.php') diff --git a/modules/forge/libraries/Form_Checkbox.php b/modules/forge/libraries/Form_Checkbox.php new file mode 100644 index 00000000..c015e437 --- /dev/null +++ b/modules/forge/libraries/Form_Checkbox.php @@ -0,0 +1,83 @@ + 'checkbox', + 'class' => 'checkbox', + 'value' => '1', + 'checked' => FALSE, + ); + + protected $protect = array('type'); + + public function __get($key) + { + if ($key == 'value') + { + // Return the value if the checkbox is checked + return $this->data['checked'] ? $this->data['value'] : NULL; + } + + return parent::__get($key); + } + + public function label($val = NULL) + { + if ($val === NULL) + { + // Do not display labels for checkboxes, labels wrap checkboxes + return ''; + } + else + { + $this->data['label'] = ($val === TRUE) ? utf8::ucwords(inflector::humanize($this->name)) : $val; + return $this; + } + } + + protected function html_element() + { + // Import the data + $data = $this->data; + + if (empty($data['checked'])) + { + // Not checked + unset($data['checked']); + } + else + { + // Is checked + $data['checked'] = 'checked'; + } + + if ($label = arr::remove('label', $data)) + { + // There must be one space before the text + $label = ' '.ltrim($label); + } + + return ''; + } + + protected function load_value() + { + if (is_bool($this->valid)) + return; + + // Makes the box checked if the value from POST is the same as the current value + $this->data['checked'] = ($this->input_value($this->name) == $this->data['value']); + } + +} // End Form Checkbox \ No newline at end of file -- cgit v1.2.3