diff --git a/system/form.php b/system/form.php index a9ed7ab2..376acff0 100644 --- a/system/form.php +++ b/system/form.php @@ -2,6 +2,13 @@ class Form { + /** + * Stores labels names. + * + * @var array + */ + private static $labels = array(); + /** * Open a HTML form. * @@ -71,6 +78,21 @@ public static function raw_token() return Session::get('csrf_token'); } + /** + * Create a HTML label element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function label($name, $value, $attributes = array()) + { + static::$labels[] = $name; + + return ''.PHP_EOL; + } + /** * Create a HTML text input element. * @@ -189,6 +211,8 @@ private static function checkable($type, $name, $value, $checked, $attributes) { $attributes['checked'] = 'checked'; } + + (in_array($name, static::$labels)) ? $attributes['id'] = $name : null; return static::input($type, $name, $value, $attributes); } @@ -204,6 +228,7 @@ private static function checkable($type, $name, $value, $checked, $attributes) public static function textarea($name, $value = '', $attributes = array()) { $attributes['name'] = $name; + (in_array($name, static::$labels)) ? $attributes['id'] = $name : null; // ------------------------------------------------------- // Set the default number of rows. @@ -236,6 +261,7 @@ public static function textarea($name, $value = '', $attributes = array()) public static function select($name, $options = array(), $selected = null, $attributes = array()) { $attributes['name'] = $name; + (in_array($name, static::$labels)) ? $attributes['id'] = $name : null; $html_options = array(); @@ -275,6 +301,7 @@ private static function input($type, $name, $value = null, $attributes = array() $attributes['type'] = $type; $attributes['name'] = $name; $attributes['value'] = $value; + (in_array($name, static::$labels)) ? $attributes['id'] = $name : null; return ''.PHP_EOL; }