Auto detect label and add id to field
This commit is contained in:
parent
efb040c507
commit
b4db6396cc
|
@ -2,6 +2,13 @@
|
||||||
|
|
||||||
class Form {
|
class Form {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores lables names.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $labels = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open a HTML form.
|
* Open a HTML form.
|
||||||
*
|
*
|
||||||
|
@ -81,6 +88,8 @@ public static function raw_token()
|
||||||
*/
|
*/
|
||||||
public static function label($name, $value, $attributes = array())
|
public static function label($name, $value, $attributes = array())
|
||||||
{
|
{
|
||||||
|
static::$labels[] = $name;
|
||||||
|
|
||||||
return '<label for="'.$name.'"'.HTML::attributes($attributes).'>'.HTML::entities($value).'</label>'.PHP_EOL;
|
return '<label for="'.$name.'"'.HTML::attributes($attributes).'>'.HTML::entities($value).'</label>'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +211,8 @@ private static function checkable($type, $name, $value, $checked, $attributes)
|
||||||
{
|
{
|
||||||
$attributes['checked'] = 'checked';
|
$attributes['checked'] = 'checked';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(in_array($name, static::$labels)) ? $attributes['id'] = $name : null;
|
||||||
|
|
||||||
return static::input($type, $name, $value, $attributes);
|
return static::input($type, $name, $value, $attributes);
|
||||||
}
|
}
|
||||||
|
@ -217,6 +228,7 @@ private static function checkable($type, $name, $value, $checked, $attributes)
|
||||||
public static function textarea($name, $value = '', $attributes = array())
|
public static function textarea($name, $value = '', $attributes = array())
|
||||||
{
|
{
|
||||||
$attributes['name'] = $name;
|
$attributes['name'] = $name;
|
||||||
|
(in_array($name, static::$labels)) ? $attributes['id'] = $name : null;
|
||||||
|
|
||||||
// -------------------------------------------------------
|
// -------------------------------------------------------
|
||||||
// Set the default number of rows.
|
// Set the default number of rows.
|
||||||
|
@ -249,6 +261,7 @@ public static function textarea($name, $value = '', $attributes = array())
|
||||||
public static function select($name, $options = array(), $selected = null, $attributes = array())
|
public static function select($name, $options = array(), $selected = null, $attributes = array())
|
||||||
{
|
{
|
||||||
$attributes['name'] = $name;
|
$attributes['name'] = $name;
|
||||||
|
(in_array($name, static::$labels)) ? $attributes['id'] = $name : null;
|
||||||
|
|
||||||
$html_options = array();
|
$html_options = array();
|
||||||
|
|
||||||
|
@ -278,6 +291,7 @@ private static function input($type, $name, $value = null, $attributes = array()
|
||||||
$attributes['type'] = $type;
|
$attributes['type'] = $type;
|
||||||
$attributes['name'] = $name;
|
$attributes['name'] = $name;
|
||||||
$attributes['value'] = $value;
|
$attributes['value'] = $value;
|
||||||
|
(in_array($name, static::$labels)) ? $attributes['id'] = $name : null;
|
||||||
|
|
||||||
return '<input'.HTML::attributes($attributes).' />'.PHP_EOL;
|
return '<input'.HTML::attributes($attributes).' />'.PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue