Refactoring the form class.

This commit is contained in:
Taylor Otwell 2011-08-08 08:59:51 -05:00
parent a94c6bd752
commit f28a2c5a4b
1 changed files with 10 additions and 18 deletions

View File

@ -145,7 +145,9 @@ public static function label($name, $value, $attributes = array())
*/
public static function input($type, $name, $value = null, $attributes = array())
{
return '<input'.HTML::attributes(array_merge($attributes, array('type' => $type, 'name' => $name, 'value' => $value, 'id' => static::id($name, $attributes)))).'>'.PHP_EOL;
$id = static::id($name, $attributes);
return '<input'.HTML::attributes(array_merge($attributes, compact('type', 'name', 'value', 'id'))).'>'.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 '<textarea'.HTML::attributes($attributes).'>'.HTML::entities($value).'</textarea>'.PHP_EOL;
}
@ -305,7 +301,9 @@ public static function select($name, $options = array(), $selected = null, $attr
foreach ($options as $value => $display)
{
$html[] = '<option'.HTML::attributes(array('value' => HTML::entities($value), 'selected' => ($value == $selected) ? 'selected' : null)).'>'.HTML::entities($display).'</option>';
$option_attributes = array('value' => HTML::entities($value), 'selected' => ($value == $selected) ? 'selected' : null);
$html[] = '<option'.HTML::attributes($option_attributes).'>'.HTML::entities($display).'</option>';
}
return '<select'.HTML::attributes($attributes).'>'.implode('', $html).'</select>'.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;
}
}