summaryrefslogtreecommitdiff
path: root/modules/forge/libraries/Form_Checkbox.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
committerBharat Mediratta <bharat@menalto.com>2008-10-31 22:12:14 +0000
commiteba717f95f586d2538007bd18da6e9b32b076c30 (patch)
tree15fc596a270f9de0d163c66c96e3c65fca5ee100 /modules/forge/libraries/Form_Checkbox.php
parentfff10f8b70376ef25722bd867df26bc5aefced43 (diff)
Merge over vendor code.
git-svn-id: http://gallery.svn.sourceforge.net/svnroot/gallery/trunk/eval/gx/gallery3/trunk@18408 57fcd75e-5312-0410-8df3-f5eb6fbb1595
Diffstat (limited to 'modules/forge/libraries/Form_Checkbox.php')
-rw-r--r--modules/forge/libraries/Form_Checkbox.php83
1 files changed, 83 insertions, 0 deletions
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 @@
+<?php
+/**
+ * FORGE checkbox input library.
+ *
+ * $Id$
+ *
+ * @package Forge
+ * @author Kohana Team
+ * @copyright (c) 2007-2008 Kohana Team
+ * @license http://kohanaphp.com/license.html
+ */
+class Form_Checkbox_Core extends Form_Input {
+
+ protected $data = array
+ (
+ 'type' => '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 '<label>'.form::input($data).$label.'</label>';
+ }
+
+ 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