From cd33e81702bf5adfc2a20f8e72dcf2c7bf2ee59c Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Sat, 2 Jul 2011 07:37:37 -0500 Subject: [PATCH] added several of the new html5 form elements. added support for attributes such as required, autofocus, etc. --- application/routes.php | 1 + system/form.php | 68 +++++++++++++++++++++++++++++++++++++++++- system/html.php | 7 +++++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/application/routes.php b/application/routes.php index e9f03c02..c457010e 100644 --- a/application/routes.php +++ b/application/routes.php @@ -19,6 +19,7 @@ 'GET /' => function() { + return Form::input('email', 'email', '', array('required', 'class' => 'awesome')); return View::make('home/index'); }, diff --git a/system/form.php b/system/form.php index 56439455..ad0b69f2 100644 --- a/system/form.php +++ b/system/form.php @@ -146,6 +146,7 @@ public static function password($name, $attributes = array()) * Create a HTML hidden input element. * * @param string $name + * @param string $value * @param array $attributes * @return string */ @@ -154,6 +155,71 @@ public static function hidden($name, $value = null, $attributes = array()) return static::input('hidden', $name, $value, $attributes); } + /** + * Create a HTML email input element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function email($name, $value = null, $attributes = array()) + { + return static::input('email', $name, $value, $attributes); + } + + /** + * Create a HTML URL input element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function url($name, $value = null, $attributes = array()) + { + return static::input('url', $name, $value, $attributes); + } + + /** + * Create a HTML search input element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function search($name, $value = null, $attributes = array()) + { + return static::input('search', $name, $value, $attributes); + } + + /** + * Create a HTML number input element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function number($name, $value = null, $attributes = array()) + { + return static::input('number', $name, $value, $attributes); + } + + /** + * Create a HTML telephone input element. + * + * @param string $name + * @param string $value + * @param array $attributes + * @return string + */ + public static function tel($name, $value = null, $attributes = array()) + { + return static::input('tel', $name, $value, $attributes); + } + /** * Create a HTML file input element. * @@ -310,7 +376,7 @@ public static function select($name, $options = array(), $selected = null, $attr * @param array $attributes * @return string */ - private static function input($type, $name, $value = null, $attributes = array()) + public static function input($type, $name, $value = null, $attributes = array()) { $attributes['type'] = $type; $attributes['name'] = $name; diff --git a/system/html.php b/system/html.php index c562de09..aba7a563 100644 --- a/system/html.php +++ b/system/html.php @@ -227,6 +227,11 @@ public static function attributes($attributes) foreach ($attributes as $key => $value) { + if (is_numeric($key)) + { + $key = $value; + } + if ( ! is_null($value)) { $html[] = $key.'="'.static::entities($value).'"'; @@ -300,6 +305,8 @@ public static function __callStatic($method, $parameters) array_unshift($parameters, substr($method, 8)); return forward_static_call_array('HTML::link_to_route', $parameters); } + + throw new \Exception("Static method [$method] is not defined on the HTML class."); } } \ No newline at end of file