]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2396: Added a new input/checkbox view. input/checkboxes harnesses it
authorewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 20 Nov 2010 09:28:42 +0000 (09:28 +0000)
committerewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544>
Sat, 20 Nov 2010 09:28:42 +0000 (09:28 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7372 36083f99-b078-4883-b0ff-0f9b5a30f544

views/default/input/checkbox.php [new file with mode: 0644]
views/default/input/checkboxes.php

diff --git a/views/default/input/checkbox.php b/views/default/input/checkbox.php
new file mode 100644 (file)
index 0000000..32bc323
--- /dev/null
@@ -0,0 +1,18 @@
+<?php
+/**
+ * Elgg checkbox input
+ * Displays a checkbox input field
+ * 
+ * @package Elgg
+ * @subpackage Core
+ */
+
+$defaults = array(
+       'class' => 'input_checkbox',
+);
+
+$vars = array_merge($defaults, $vars);
+
+?>
+
+<input type="checkbox" <?php echo elgg_format_attributes($vars); ?> />
\ No newline at end of file
index adfe1991421a67fbc0b8d3af7dd98537dc6d0ba7..46254633bfa0315a8444f24ad91f90201dfff1ce 100644 (file)
@@ -52,44 +52,24 @@ if ($options) {
                        $label = $option;
                }
 
-               if (!in_array(strtolower($option), $value_array)) {
-                       $selected = FALSE;
-               } else {
-                       $selected = TRUE;
-               }
-
-               $attr = array(
-                       'type="checkbox"',
-                       'value="' . htmlentities($option, ENT_QUOTES, 'UTF-8') . '"'
+               $input_vars = array(
+                       'checked' => in_array(strtolower($option), $value_array),
+                       'value' => $option,
+                       'disabled' => $disabled,
+                       'id' => $id,
+                       'js' => $js,
                );
-
-               if ($id) {
-                       $attr[] = "id=\"$id\"";
-               }
-
+               
                if ($class) {
-                       $attr[] = "class=\"$class\"";
-               }
-
-               if ($disabled) {
-                       $attr[] = 'disabled="yes"';
-               }
-
-               if ($selected) {
-                       $attr[] = 'checked = "checked"';
-               }
-
-               if ($js) {
-                       $attr[] = $js;
+                       $input_vars['class'] = $class;
                }
 
                if ($internalname) {
-                       // @todo this really, really should only add the []s if there are > 1 element in options.
-                       $attr[] = "name=\"{$internalname}[]\"";
+                       $input_vars['name'] = "{$internalname}[]";
                }
+               
+               $input = elgg_view('input/checkbox', $input_vars);
 
-               $attr_str = implode(' ', $attr);
-
-               echo "<label><input $attr_str />$label</label><br />";
+               echo "<label>{$input}{$label}</label><br />";
        }
 }
\ No newline at end of file