From f28a2c5a4b03c2f4f472d23e58cca97f5c4581bc Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 8 Aug 2011 08:59:51 -0500 Subject: [PATCH] Refactoring the form class. --- system/form.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/system/form.php b/system/form.php index 574ab584..9e67d25f 100644 --- a/system/form.php +++ b/system/form.php @@ -145,7 +145,9 @@ public static function label($name, $value, $attributes = array()) */ public static function input($type, $name, $value = null, $attributes = array()) { - return ' $type, 'name' => $name, 'value' => $value, 'id' => static::id($name, $attributes)))).'>'.PHP_EOL; + $id = static::id($name, $attributes); + + return ''.PHP_EOL; } /** @@ -275,15 +277,9 @@ public static function textarea($name, $value = '', $attributes = array()) { $attributes = array_merge($attributes, array('id' => static::id($name, $attributes), 'name' => $name)); - if ( ! isset($attributes['rows'])) - { - $attributes['rows'] = 10; - } + if ( ! isset($attributes['rows'])) $attributes['rows'] = 10; - if ( ! isset($attributes['cols'])) - { - $attributes['cols'] = 50; - } + if ( ! isset($attributes['cols'])) $attributes['cols'] = 50; return ''.HTML::entities($value).''.PHP_EOL; } @@ -305,7 +301,9 @@ public static function select($name, $options = array(), $selected = null, $attr foreach ($options as $value => $display) { - $html[] = ' HTML::entities($value), 'selected' => ($value == $selected) ? 'selected' : null)).'>'.HTML::entities($display).''; + $option_attributes = array('value' => HTML::entities($value), 'selected' => ($value == $selected) ? 'selected' : null); + + $html[] = ''.HTML::entities($display).''; } return ''.implode('', $html).''.PHP_EOL; @@ -419,15 +417,9 @@ public static function button($value, $attributes = array()) */ private static function id($name, $attributes) { - if (array_key_exists('id', $attributes)) - { - return $attributes['id']; - } + if (array_key_exists('id', $attributes)) return $attributes['id']; - if (in_array($name, static::$labels)) - { - return $name; - } + if (in_array($name, static::$labels)) return $name; } } \ No newline at end of file