From 9b6663f87a7e679ffba691cf516191fc840cf978 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 24 Nov 2009 19:20:36 -0800 Subject: Update to Kohana r4684 which is now Kohana 2.4 and has substantial changes. --- system/helpers/form.php | 123 +++++++++++++----------------------------------- 1 file changed, 34 insertions(+), 89 deletions(-) (limited to 'system/helpers/form.php') diff --git a/system/helpers/form.php b/system/helpers/form.php index 815eef84..901edc91 100644 --- a/system/helpers/form.php +++ b/system/helpers/form.php @@ -2,12 +2,12 @@ /** * Form helper class. * - * $Id: form.php 4291 2009-04-29 22:51:58Z kiall $ + * $Id: form.php 4679 2009-11-10 01:45:52Z isaiah $ * * @package Core * @author Kohana Team - * @copyright (c) 2007-2008 Kohana Team - * @license http://kohanaphp.com/license.html + * @copyright (c) 2007-2009 Kohana Team + * @license http://kohanaphp.com/license */ class form_Core { @@ -17,9 +17,10 @@ class form_Core { * @param string form action attribute * @param array extra attributes * @param array hidden fields to be created immediately after the form tag + * @param string non-default protocol, eg: https * @return string */ - public static function open($action = NULL, $attr = array(), $hidden = NULL) + public static function open($action = NULL, $attr = array(), $hidden = NULL, $protocol = NULL) { // Make sure that the method is always set empty($attr['method']) and $attr['method'] = 'post'; @@ -33,12 +34,12 @@ class form_Core { if ($action === NULL) { // Use the current URL as the default action - $action = url::site(Router::$complete_uri); + $action = url::site(Router::$complete_uri, $protocol); } elseif (strpos($action, '://') === FALSE) { // Make the action URI into a URL - $action = url::site($action); + $action = url::site($action, $protocol); } // Set action @@ -70,72 +71,23 @@ class form_Core { } /** - * Generates a fieldset opening tag. + * Creates a HTML form hidden input tag. * - * @param array html attributes - * @param string a string to be attached to the end of the attributes - * @return string - */ - public static function open_fieldset($data = NULL, $extra = '') - { - return ''."\n"; - } - - /** - * Generates a fieldset closing tag. - * - * @return string - */ - public static function close_fieldset() - { - return ''."\n"; - } - - /** - * Generates a legend tag for use with a fieldset. - * - * @param string legend text - * @param array HTML attributes - * @param string a string to be attached to the end of the attributes - * @return string - */ - public static function legend($text = '', $data = NULL, $extra = '') - { - return ''.$text.''."\n"; - } - - /** - * Generates hidden form fields. - * You can pass a simple key/value string or an associative array with multiple values. - * - * @param string|array input name (string) or key/value pairs (array) - * @param string input value, if using an input name + * @param string|array input name or an array of HTML attributes + * @param string input value, when using a name + * @param string a string to be attached to the end of the attributes * @return string */ - public static function hidden($data, $value = '') + public static function hidden($data, $value = '', $extra = '') { if ( ! is_array($data)) { - $data = array - ( - $data => $value - ); + $data = array('name' => $data); } - $input = ''; - foreach ($data as $name => $value) - { - $attr = array - ( - 'type' => 'hidden', - 'name' => $name, - 'value' => $value - ); - - $input .= form::input($attr)."\n"; - } + $data['type'] = 'hidden'; - return $input; + return form::input($data, $value, $extra); } /** @@ -219,13 +171,23 @@ class form_Core { $data = array('name' => $data); } + if ( ! isset($data['rows'])) + { + $data['rows'] = ''; + } + + if ( ! isset($data['cols'])) + { + $data['cols'] = ''; + } + // Use the value from $data if possible, or use $value $value = isset($data['value']) ? $data['value'] : $value; // Value is not part of the attributes unset($data['value']); - return ''.html::specialchars($value, $double_encode).''; + return ''.htmlspecialchars($value, ENT_QUOTES, Kohana::CHARSET, $double_encode).''; } /** @@ -283,21 +245,15 @@ class form_Core { // Inner key should always be a string $inner_key = (string) $inner_key; - $attr = array('value' => $inner_key); - if (in_array($inner_key, $selected)) { - $attr['selected'] = 'selected'; - } - $input .= ''."\n"; + $sel = in_array($inner_key, $selected) ? ' selected="selected"' : ''; + $input .= ''."\n"; } $input .= ''."\n"; } else { - $attr = array('value' => $key); - if (in_array($key, $selected)) { - $attr['selected'] = 'selected'; - } - $input .= ''."\n"; + $sel = in_array($key, $selected) ? ' selected="selected"' : ''; + $input .= ''."\n"; } } $input .= ''; @@ -416,20 +372,8 @@ class form_Core { { $value = arr::remove('value', $data); } - // $value must be ::purify - - return ''.html::purify($value).''; - } - /** - * Closes an open form tag. - * - * @param string string to be attached after the closing tag - * @return string - */ - public static function close($extra = '') - { - return ''."\n".$extra; + return ''.$value.''; } /** @@ -462,7 +406,7 @@ class form_Core { $text = ucwords(inflector::humanize($data['for'])); } - return ''.html::purify($text).''; + return ''.$text.''; } /** @@ -496,6 +440,7 @@ class form_Core { case 'image': case 'button': case 'submit': + case 'hidden': // Only specific types of inputs use name to id matching $attr['id'] = $attr['name']; break; @@ -546,4 +491,4 @@ class form_Core { return html::attributes(array_merge($sorted, $attr)); } -} // End form \ No newline at end of file +} // End form -- cgit v1.2.3