From b0dd10f8171945e0c1f3527dd1e9d18b043e01a7 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 25 Aug 2006 17:25:49 +0000 Subject: Initial Import --- system/helpers/form_helper.php | 382 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 system/helpers/form_helper.php (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php new file mode 100644 index 000000000..f82ad01a0 --- /dev/null +++ b/system/helpers/form_helper.php @@ -0,0 +1,382 @@ +config->site_url($action).'"'; + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Dropdown Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (isset($data['checked'])) + { + $checked = $data['checked']; + + if ($checked == FALSE) + unset($data['checked']); + } + + if ($checked == TRUE) + $defaults['checked'] = ' checked="checked"'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str == '') + { + return ''; + } + + return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str)); +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @parm array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From b071bb5a92aade551345a495fb13f5678f3978d0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 26 Aug 2006 19:28:37 +0000 Subject: --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index f82ad01a0..d4e45a0af 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -326,7 +326,7 @@ function form_close($extra = '') */ function form_prep($str = '') { - if ($str == '') + if ($str === '') { return ''; } -- cgit v1.2.3-24-g4f1b From 141808ad31d4eefad4c6c3dbaf8306fac2342668 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 01:52:51 +0000 Subject: --- system/helpers/form_helper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d4e45a0af..069101063 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -38,11 +38,16 @@ * @param array a key/value pair hidden data * @return string */ -function form_open($action, $attributes = array(), $hidden = array()) +function form_open($action = '', $attributes = array(), $hidden = array()) { $obj =& get_instance(); - $form = '
config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } if (is_array($attributes) AND count($attributes) > 0) { -- cgit v1.2.3-24-g4f1b From 57b3d39cb79bb3b8d193e0e345a62e3396e519f2 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 27 Aug 2006 15:28:31 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 069101063..eb97913f1 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -247,7 +247,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - if (isset($data['checked'])) + if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; @@ -256,7 +256,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') } if ($checked == TRUE) - $defaults['checked'] = ' checked="checked"'; + $defaults['checked'] = 'checked'; else unset($defaults['checked']); -- cgit v1.2.3-24-g4f1b From 75198f97ba9df6e5696ac295820d9d73a4e4f441 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 7 Oct 2006 03:16:53 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index eb97913f1..3fd361041 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,9 +40,9 @@ */ function form_open($action = '', $attributes = array(), $hidden = array()) { - $obj =& get_instance(); + $CI =& get_instance(); - $form = 'config->site_url($action).'"'; if ( ! isset($attributes['method'])) { -- cgit v1.2.3-24-g4f1b From fafe28bec4f414e48f63e01ed9105ae5c2c99802 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:08:17 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 3fd361041..e12d89319 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -204,7 +204,7 @@ function form_textarea($data = '', $value = '', $extra = '') // ------------------------------------------------------------------------ /** - * Dropdown Menu + * Drop-down Menu * * @access public * @param string @@ -348,7 +348,7 @@ function form_prep($str = '') * * @access private * @param array - * @parm array + * @param array * @return string */ function parse_form_attributes($attributes, $default) -- cgit v1.2.3-24-g4f1b From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 21 Oct 2006 19:44:22 +0000 Subject: --- system/helpers/form_helper.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e12d89319..6d10a9862 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -7,12 +7,12 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, pMachine, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeignitor.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource */ - + // ------------------------------------------------------------------------ /** @@ -53,7 +53,7 @@ function form_open($action = '', $attributes = array(), $hidden = array()) { foreach ($attributes as $key => $val) { - $form .= ' '.$key.'="'.$val.'"'; + $form .= ' '.$key.'="'.$val.'"'; } } @@ -100,7 +100,7 @@ function form_open_multipart($action, $attributes = array(), $hidden = array()) * @return string */ function form_hidden($name, $value = '') -{ +{ if ( ! is_array($name)) { return ''; @@ -251,7 +251,7 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $checked = $data['checked']; - if ($checked == FALSE) + if ($checked == FALSE) unset($data['checked']); } -- cgit v1.2.3-24-g4f1b From 7acd581d9441fb8ada4c46c58f4ec30a01507506 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 23 Oct 2006 21:37:22 +0000 Subject: --- system/helpers/form_helper.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 6d10a9862..7d594d72c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -335,8 +335,24 @@ function form_prep($str = '') { return ''; } + + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = htmlspecialchars($str); + + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - return str_replace(array("'", '"'), array("'", """), htmlspecialchars($str)); + return $str; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b From 17f4d73ff388dbcb4d9fbd4f79a0f9150ddc8c7e Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sat, 27 Jan 2007 17:23:13 +0000 Subject: unset the value attribute in textarea --- system/helpers/form_helper.php | 806 +++++++++++++++++++++-------------------- 1 file changed, 404 insertions(+), 402 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7d594d72c..8186d4ccd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,403 +1,405 @@ -config->site_url($action).'"'; - - if ( ! isset($attributes['method'])) - { - $form .= ' method="post"'; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } - - $form .= '>'; - - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) -{ - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); -} - -// ------------------------------------------------------------------------ - -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ -function form_hidden($name, $value = '') -{ - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_input($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_password($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_upload($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_textarea($data = '', $value = '', $extra = '') -{ - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') -{ - if ($extra != '') $extra = ' '.$extra; - - $form = ''; - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') -{ - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - unset($data['checked']); - } - - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -function form_close($extra = '') -{ - return "\n".$extra; -} - -// ------------------------------------------------------------------------ - -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ -function form_prep($str = '') -{ - if ($str === '') - { - return ''; - } - - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = htmlspecialchars($str); - - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @return string - */ -function parse_form_attributes($attributes, $default) -{ - if (is_array($attributes)) - { - foreach ($default as $key => $val) - { - if (isset($attributes[$key])) - { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); - } - } - - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); - } - } - - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') - { - $val = form_prep($val); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; -} - +config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); + + unset ($data['value']); // textareas don't use the value attribute + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + unset($data['checked']); + } + + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str === '') + { + return ''; + } + + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = htmlspecialchars($str); + + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @param array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c4ac15f47a73a2db99406d901d53803b87f255bb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 15 Feb 2007 17:22:31 +0000 Subject: fixed a a value bug introduced when clearing value from textarea --- system/helpers/form_helper.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8186d4ccd..a166198fb 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -196,9 +196,15 @@ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - $val = (( ! is_array($data) OR ! isset($data['value'])) ? $value : $data['value']); - - unset ($data['value']); // textareas don't use the value attribute + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } return "\n"; } -- cgit v1.2.3-24-g4f1b From d2df9bc7cc9d4b3e53818470c5d0977c9a36677c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 15 Apr 2007 17:41:17 +0000 Subject: update pMachine to EllisLab update copyright year update Code Igniter to CodeIgniter --- system/helpers/form_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a166198fb..adbddd5ad 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,12 +1,12 @@ Date: Fri, 27 Apr 2007 03:33:21 +0000 Subject: fixed checked = 1 to be checked = checked in array created checkboxes --- system/helpers/form_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index adbddd5ad..531ab66c0 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -260,7 +260,13 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') $checked = $data['checked']; if ($checked == FALSE) + { unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } } if ($checked == TRUE) -- cgit v1.2.3-24-g4f1b From c80593c537117b11e2f75287fc9a18e0d0d2bf5a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 11 Jul 2007 23:40:14 +0000 Subject: type cast $key => $val pair in $options array as strings for friendlier handling of setting options as 'selected' --- system/helpers/form_helper.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 531ab66c0..263dc0f19 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -229,6 +229,9 @@ function form_dropdown($name = '', $options = array(), $selected = '', $extra = foreach ($options as $key => $val) { + $key = (string) $key; + $val = (string) $val; + $sel = ($selected != $key) ? '' : ' selected="selected"'; $form .= '\n"; -- cgit v1.2.3-24-g4f1b From 6838f00a708f53f834fb8a98af560177db1d1454 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 4 Oct 2007 19:29:59 +0000 Subject: Fixed a typo in the docblock comments that had CodeIgniter spelled CodeIgnitor. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 263dc0f19..17022a3b3 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -7,7 +7,7 @@ * @package CodeIgniter * @author Rick Ellis * @copyright Copyright (c) 2006, EllisLab, Inc. - * @license http://www.codeignitor.com/user_guide/license.html + * @license http://www.codeigniter.com/user_guide/license.html * @link http://www.codeigniter.com * @since Version 1.0 * @filesource -- cgit v1.2.3-24-g4f1b From c3d8e6a78ea47e9133ed426fef4b0e4650e64d3d Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 17 Dec 2007 13:50:46 +0000 Subject: Added form_reset() function to form helper. --- system/helpers/form_helper.php | 421 +---------------------------------------- 1 file changed, 1 insertion(+), 420 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 17022a3b3..a23d4c6d2 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,420 +1 @@ -config->site_url($action).'"'; - - if ( ! isset($attributes['method'])) - { - $form .= ' method="post"'; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } - - $form .= '>'; - - if (is_array($hidden) AND count($hidden > 0)) - { - $form .= form_hidden($hidden); - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ -function form_open_multipart($action, $attributes = array(), $hidden = array()) -{ - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); -} - -// ------------------------------------------------------------------------ - -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ -function form_hidden($name, $value = '') -{ - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_input($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_password($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_upload($data = '', $value = '', $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_textarea($data = '', $value = '', $extra = '') -{ - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - if ( ! is_array($data) OR ! isset($data['value'])) - { - $val = $value; - } - else - { - $val = $data['value']; - unset($data['value']); // textareas don't use the value attribute - } - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') -{ - if ($extra != '') $extra = ' '.$extra; - - $form = ''; - - return $form; -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') -{ - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else - { - $data['checked'] = 'checked'; - } - } - - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') -{ - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); -} - -// ------------------------------------------------------------------------ - -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return "\n"; -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -function form_close($extra = '') -{ - return "\n".$extra; -} - -// ------------------------------------------------------------------------ - -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ -function form_prep($str = '') -{ - if ($str === '') - { - return ''; - } - - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = htmlspecialchars($str); - - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; -} - -// ------------------------------------------------------------------------ - -/** - * Parse the form attributes - * - * Helper function used by some of the form helpers - * - * @access private - * @param array - * @param array - * @return string - */ -function parse_form_attributes($attributes, $default) -{ - if (is_array($attributes)) - { - foreach ($default as $key => $val) - { - if (isset($attributes[$key])) - { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); - } - } - - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); - } - } - - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') - { - $val = form_prep($val); - } - - $att .= $key . '="' . $val . '" '; - } - - return $att; -} - -?> \ No newline at end of file +config->site_url($action).'"'; if ( ! isset($attributes['method'])) { $form .= ' method="post"'; } if (is_array($attributes) AND count($attributes) > 0) { foreach ($attributes as $key => $val) { $form .= ' '.$key.'="'.$val.'"'; } } $form .= '>'; if (is_array($hidden) AND count($hidden > 0)) { $form .= form_hidden($hidden); } return $form; } // ------------------------------------------------------------------------ /** * Form Declaration - Multipart type * * Creates the opening portion of the form, but with "multipart/form-data". * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ function form_open_multipart($action, $attributes = array(), $hidden = array()) { $attributes['enctype'] = 'multipart/form-data'; return form_open($action, $attributes, $hidden); } // ------------------------------------------------------------------------ /** * Hidden Input Field * * Generates hidden fields. You can pass a simple key/value string or an associative * array with multiple values. * * @access public * @param mixed * @param string * @return string */ function form_hidden($name, $value = '') { if ( ! is_array($name)) { return ''; } $form = ''; foreach ($name as $name => $value) { $form .= ''; } return $form; } // ------------------------------------------------------------------------ /** * Text Input Field * * @access public * @param mixed * @param string * @param string * @return string */ function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } // ------------------------------------------------------------------------ /** * Password Field * * Identical to the input function but adds the "password" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'password'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Upload Field * * Identical to the input function but adds the "file" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'file'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Textarea field * * @access public * @param mixed * @param string * @param string * @return string */ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } return "\n"; } // ------------------------------------------------------------------------ /** * Drop-down Menu * * @access public * @param string * @param array * @param string * @param string * @return string */ function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') { if ($extra != '') $extra = ' '.$extra; $form = ''; return $form; } // ------------------------------------------------------------------------ /** * Checkbox Field * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; if ($checked == FALSE) { unset($data['checked']); } else { $data['checked'] = 'checked'; } } if ($checked == TRUE) $defaults['checked'] = 'checked'; else unset($defaults['checked']); return "\n"; } // ------------------------------------------------------------------------ /** * Radio Button * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'radio'; return form_checkbox($data, $value, $checked, $extra); } // ------------------------------------------------------------------------ /** * Submit Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Reset Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Form Close Tag * * @access public * @param string * @return string */ function form_close($extra = '') { return "\n".$extra; } // ------------------------------------------------------------------------ /** * Form Prep * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * * @access public * @param string * @return string */ function form_prep($str = '') { if ($str === '') { return ''; } $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that // htmlspecialchars won't mess them up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("'", """), $str); // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); $str = preg_replace("/$temp(\w+);/","&\\1;",$str); return $str; } // ------------------------------------------------------------------------ /** * Parse the form attributes * * Helper function used by some of the form helpers * * @access private * @param array * @param array * @return string */ function parse_form_attributes($attributes, $default) { if (is_array($attributes)) { foreach ($default as $key => $val) { if (isset($attributes[$key])) { $default[$key] = $attributes[$key]; unset($attributes[$key]); } } if (count($attributes) > 0) { $default = array_merge($default, $attributes); } } $att = ''; foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val); } $att .= $key . '="' . $val . '" '; } return $att; } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f3e8a3508a4c9bfc203ce861a73e989dc4771f49 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 4 Jan 2008 14:30:38 +0000 Subject: Added form_fieldset(), form_fieldset_close(), and form_label() to form helper. --- system/helpers/form_helper.php | 524 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 523 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a23d4c6d2..e591eb74c 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1 +1,523 @@ -config->site_url($action).'"'; if ( ! isset($attributes['method'])) { $form .= ' method="post"'; } if (is_array($attributes) AND count($attributes) > 0) { foreach ($attributes as $key => $val) { $form .= ' '.$key.'="'.$val.'"'; } } $form .= '>'; if (is_array($hidden) AND count($hidden > 0)) { $form .= form_hidden($hidden); } return $form; } // ------------------------------------------------------------------------ /** * Form Declaration - Multipart type * * Creates the opening portion of the form, but with "multipart/form-data". * * @access public * @param string the URI segments of the form destination * @param array a key/value pair of attributes * @param array a key/value pair hidden data * @return string */ function form_open_multipart($action, $attributes = array(), $hidden = array()) { $attributes['enctype'] = 'multipart/form-data'; return form_open($action, $attributes, $hidden); } // ------------------------------------------------------------------------ /** * Hidden Input Field * * Generates hidden fields. You can pass a simple key/value string or an associative * array with multiple values. * * @access public * @param mixed * @param string * @return string */ function form_hidden($name, $value = '') { if ( ! is_array($name)) { return ''; } $form = ''; foreach ($name as $name => $value) { $form .= ''; } return $form; } // ------------------------------------------------------------------------ /** * Text Input Field * * @access public * @param mixed * @param string * @param string * @return string */ function form_input($data = '', $value = '', $extra = '') { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } // ------------------------------------------------------------------------ /** * Password Field * * Identical to the input function but adds the "password" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_password($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'password'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Upload Field * * Identical to the input function but adds the "file" type * * @access public * @param mixed * @param string * @param string * @return string */ function form_upload($data = '', $value = '', $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'file'; return form_input($data, $value, $extra); } // ------------------------------------------------------------------------ /** * Textarea field * * @access public * @param mixed * @param string * @param string * @return string */ function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } return "\n"; } // ------------------------------------------------------------------------ /** * Drop-down Menu * * @access public * @param string * @param array * @param string * @param string * @return string */ function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') { if ($extra != '') $extra = ' '.$extra; $form = ''; return $form; } // ------------------------------------------------------------------------ /** * Checkbox Field * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; if ($checked == FALSE) { unset($data['checked']); } else { $data['checked'] = 'checked'; } } if ($checked == TRUE) $defaults['checked'] = 'checked'; else unset($defaults['checked']); return "\n"; } // ------------------------------------------------------------------------ /** * Radio Button * * @access public * @param mixed * @param string * @param bool * @param string * @return string */ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') { if ( ! is_array($data)) { $data = array('name' => $data); } $data['type'] = 'radio'; return form_checkbox($data, $value, $checked, $extra); } // ------------------------------------------------------------------------ /** * Submit Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_submit($data = '', $value = '', $extra = '') { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Reset Button * * @access public * @param mixed * @param string * @param string * @return string */ function form_reset($data = '', $value = '', $extra = '') { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } // ------------------------------------------------------------------------ /** * Form Close Tag * * @access public * @param string * @return string */ function form_close($extra = '') { return "\n".$extra; } // ------------------------------------------------------------------------ /** * Form Prep * * Formats text so that it can be safely placed in a form field in the event it has HTML tags. * * @access public * @param string * @return string */ function form_prep($str = '') { if ($str === '') { return ''; } $temp = '__TEMP_AMPERSANDS__'; // Replace entities to temporary markers so that // htmlspecialchars won't mess them up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("'", """), $str); // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); $str = preg_replace("/$temp(\w+);/","&\\1;",$str); return $str; } // ------------------------------------------------------------------------ /** * Parse the form attributes * * Helper function used by some of the form helpers * * @access private * @param array * @param array * @return string */ function parse_form_attributes($attributes, $default) { if (is_array($attributes)) { foreach ($default as $key => $val) { if (isset($attributes[$key])) { $default[$key] = $attributes[$key]; unset($attributes[$key]); } } if (count($attributes) > 0) { $default = array_merge($default, $attributes); } } $att = ''; foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val); } $att .= $key . '="' . $val . '" '; } return $att; } ?> \ No newline at end of file +config->site_url($action).'"'; + + if ( ! isset($attributes['method'])) + { + $form .= ' method="post"'; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + foreach ($attributes as $key => $val) + { + $form .= ' '.$key.'="'.$val.'"'; + } + } + + $form .= '>'; + + if (is_array($hidden) AND count($hidden > 0)) + { + $form .= form_hidden($hidden); + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Form Declaration - Multipart type + * + * Creates the opening portion of the form, but with "multipart/form-data". + * + * @access public + * @param string the URI segments of the form destination + * @param array a key/value pair of attributes + * @param array a key/value pair hidden data + * @return string + */ +function form_open_multipart($action, $attributes = array(), $hidden = array()) +{ + $attributes['enctype'] = 'multipart/form-data'; + return form_open($action, $attributes, $hidden); +} + +// ------------------------------------------------------------------------ + +/** + * Hidden Input Field + * + * Generates hidden fields. You can pass a simple key/value string or an associative + * array with multiple values. + * + * @access public + * @param mixed + * @param string + * @return string + */ +function form_hidden($name, $value = '') +{ + if ( ! is_array($name)) + { + return ''; + } + + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_input($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_password($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_upload($data = '', $value = '', $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_textarea($data = '', $value = '', $extra = '') +{ + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +{ + if ($extra != '') $extra = ' '.$extra; + + $form = ''; + + return $form; +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +{ + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } + } + + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +{ + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_submit($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Reset Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +function form_reset($data = '', $value = '', $extra = '') +{ + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return "\n"; +} + +// ------------------------------------------------------------------------ + +/** + * Form Label Tag + * + * @access public + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param string Additional attributes + * @return string + */ +function form_label($label_text = '', $id = '', $attributes = array()) +{ + + $label = ' 0) + { + foreach ($attributes as $key => $val) + { + $label .= ' '.$key.'="'.$val.'"'; + } + } + + $label .= ">$label_text"; + + return $label; +} + +// ------------------------------------------------------------------------ +/** + * Fieldset Tag + * + * Used to produce
text. To close fieldset + * use form_fieldset_close() + * + * @access public + * @param string The legend text + * @param string Additional attributes + * @return string + */ +function form_fieldset($legend_text = '', $attributes = array()) +{ + + $fieldset = " 0) + { + foreach ($attributes as $key => $val) + { + $fieldset .= ' '.$key.'="'.$val.'"'; + } + } + + $fieldset .= ">\n"; + + if ($legend_text != '') + { + $fieldset .= "$legend_text\n"; + } + + + + return $fieldset; +} + +// ------------------------------------------------------------------------ + +/** + * Fieldset Close Tag + * + * @access public + * @param string + * @return string + */ +function form_fieldset_close($extra = '') +{ + return "
\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +function form_close($extra = '') +{ + return "\n".$extra; +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +function form_prep($str = '') +{ + if ($str === '') + { + return ''; + } + + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = htmlspecialchars($str); + + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; +} + +// ------------------------------------------------------------------------ + +/** + * Parse the form attributes + * + * Helper function used by some of the form helpers + * + * @access private + * @param array + * @param array + * @return string + */ +function parse_form_attributes($attributes, $default) +{ + if (is_array($attributes)) + { + foreach ($default as $key => $val) + { + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } + } + + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } + } + + $att = ''; + foreach ($default as $key => $val) + { + if ($key == 'value') + { + $val = form_prep($val); + } + + $att .= $key . '="' . $val . '" '; + } + + return $att; +} + +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 4021b51750afb7e39dc0e5ea6e839c7da4e069ab Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 4 Jan 2008 22:26:12 +0000 Subject: added the ability to have multiple selected items in form_dropdown() --- system/helpers/form_helper.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index e591eb74c..a67ea050d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -221,18 +221,24 @@ function form_textarea($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_dropdown($name = '', $options = array(), $selected = '', $extra = '') +function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { + if ( ! is_array($selected)) + { + $selected = array($selected); + } + if ($extra != '') $extra = ' '.$extra; - - $form = '\n"; foreach ($options as $key => $val) { $key = (string) $key; $val = (string) $val; - $sel = ($selected != $key) ? '' : ' selected="selected"'; + $sel = (in_array($key, $selected))?' selected="selected"':''; $form .= '\n"; } -- cgit v1.2.3-24-g4f1b From 56e5722f2861f0e4c2bd0c9bb4e9d5065dd0a5b0 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 9 Jan 2008 19:43:40 +0000 Subject: bugfix --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a67ea050d..1d2cb8604 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -229,7 +229,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected > 1))?' multiple="multiple"':''; + $multiple = (count($selected) > 1)?' multiple="multiple"':''; $form = '\n"; -- cgit v1.2.3-24-g4f1b From 76708b780c558c0d5db1efd8e11787269e0507e3 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 15 Jan 2008 23:58:19 +0000 Subject: bug(re)fix: I am so smart. s - m - r - t --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3bc9d81..9f3509d51 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -231,7 +231,7 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected > 1))?' multiple="multiple"':''; + $multiple = (count($selected) > 1))?' multiple="multiple"':''; $form = '\n"; -- cgit v1.2.3-24-g4f1b From f8f05703f61689b4d0b432f12e36a27f15778458 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 18 Jan 2008 14:39:23 +0000 Subject: added check for "multiple" attribute in form_dropdown() (bug# 3261) --- system/helpers/form_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c3a3ccb5b..a727f4715 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -231,7 +231,8 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext } if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected) > 1) ? ' multiple="multiple"' : ''; + + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; $form = ''; - } + if ( ! is_array($name)) + { + return ''; + } - $form = ''; - foreach ($name as $name => $value) - { - $form .= ''; - } + $form = ''; + foreach ($name as $name => $value) + { + $form .= ''; + } - return $form; + return $form; + } } // ------------------------------------------------------------------------ @@ -128,11 +137,14 @@ function form_hidden($name, $value = '') * @param string * @return string */ -function form_input($data = '', $value = '', $extra = '') +if (! function_exists('form_input')) { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + function form_input($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -148,15 +160,18 @@ function form_input($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_password($data = '', $value = '', $extra = '') +if (! function_exists('form_password')) { - if ( ! is_array($data)) + function form_password($data = '', $value = '', $extra = '') { - $data = array('name' => $data); - } + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'password'; - return form_input($data, $value, $extra); + $data['type'] = 'password'; + return form_input($data, $value, $extra); + } } // ------------------------------------------------------------------------ @@ -172,15 +187,18 @@ function form_password($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_upload($data = '', $value = '', $extra = '') +if (! function_exists('form_upload')) { - if ( ! is_array($data)) + function form_upload($data = '', $value = '', $extra = '') { - $data = array('name' => $data); - } + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'file'; - return form_input($data, $value, $extra); + $data['type'] = 'file'; + return form_input($data, $value, $extra); + } } // ------------------------------------------------------------------------ @@ -194,21 +212,24 @@ function form_upload($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_textarea($data = '', $value = '', $extra = '') +if (! function_exists('form_textarea')) { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - if ( ! is_array($data) OR ! isset($data['value'])) - { - $val = $value; - } - else + function form_textarea($data = '', $value = '', $extra = '') { - $val = $data['value']; - unset($data['value']); // textareas don't use the value attribute - } + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -223,32 +244,35 @@ function form_textarea($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') +if (! function_exists('form_dropdown')) { - if ( ! is_array($selected)) + function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - $selected = array($selected); - } + if ( ! is_array($selected)) + { + $selected = array($selected); + } - if ($extra != '') $extra = ' '.$extra; + if ($extra != '') $extra = ' '.$extra; - $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; - $form = '\n"; - foreach ($options as $key => $val) - { - $key = (string) $key; - $val = (string) $val; + foreach ($options as $key => $val) + { + $key = (string) $key; + $val = (string) $val; - $sel = (in_array($key, $selected))?' selected="selected"':''; + $sel = (in_array($key, $selected))?' selected="selected"':''; - $form .= '\n"; - } + $form .= '\n"; + } - $form .= ''; + $form .= ''; - return $form; + return $form; + } } // ------------------------------------------------------------------------ @@ -263,30 +287,33 @@ function form_dropdown($name = '', $options = array(), $selected = array(), $ext * @param string * @return string */ -function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') +if (! function_exists('form_checkbox')) { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) + function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) { - $data['checked'] = 'checked'; + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } } - } - if ($checked == TRUE) - $defaults['checked'] = 'checked'; - else - unset($defaults['checked']); + if ($checked == TRUE) + $defaults['checked'] = 'checked'; + else + unset($defaults['checked']); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -301,15 +328,18 @@ function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') * @param string * @return string */ -function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') +if (! function_exists('form_radio')) { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } + function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') + { + if ( ! is_array($data)) + { + $data = array('name' => $data); + } - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); + } } // ------------------------------------------------------------------------ @@ -322,12 +352,15 @@ function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') * @param string * @param string * @return string - */ -function form_submit($data = '', $value = '', $extra = '') -{ - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + */ +if (! function_exists('form_submit')) +{ + function form_submit($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -341,11 +374,14 @@ function form_submit($data = '', $value = '', $extra = '') * @param string * @return string */ -function form_reset($data = '', $value = '', $extra = '') +if (! function_exists('form_reset')) { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + function form_reset($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return "\n"; + } } // ------------------------------------------------------------------------ @@ -359,27 +395,30 @@ function form_reset($data = '', $value = '', $extra = '') * @param string Additional attributes * @return string */ -function form_label($label_text = '', $id = '', $attributes = array()) +if (! function_exists('form_label')) { + function form_label($label_text = '', $id = '', $attributes = array()) + { - $label = ' 0) - { - foreach ($attributes as $key => $val) + if (is_array($attributes) AND count($attributes) > 0) { - $label .= ' '.$key.'="'.$val.'"'; + foreach ($attributes as $key => $val) + { + $label .= ' '.$key.'="'.$val.'"'; + } } - } - $label .= ">$label_text"; + $label .= ">$label_text"; - return $label; + return $label; + } } // ------------------------------------------------------------------------ @@ -394,29 +433,32 @@ function form_label($label_text = '', $id = '', $attributes = array()) * @param string Additional attributes * @return string */ -function form_fieldset($legend_text = '', $attributes = array()) +if (! function_exists('form_fieldset')) { + function form_fieldset($legend_text = '', $attributes = array()) + { - $fieldset = " 0) - { - foreach ($attributes as $key => $val) + if (is_array($attributes) AND count($attributes) > 0) { - $fieldset .= ' '.$key.'="'.$val.'"'; + foreach ($attributes as $key => $val) + { + $fieldset .= ' '.$key.'="'.$val.'"'; + } } - } - $fieldset .= ">\n"; + $fieldset .= ">\n"; - if ($legend_text != '') - { - $fieldset .= "$legend_text\n"; - } + if ($legend_text != '') + { + $fieldset .= "$legend_text\n"; + } - return $fieldset; + return $fieldset; + } } // ------------------------------------------------------------------------ @@ -428,9 +470,12 @@ function form_fieldset($legend_text = '', $attributes = array()) * @param string * @return string */ -function form_fieldset_close($extra = '') +if (! function_exists('form_fieldset_close')) { - return "\n".$extra; + function form_fieldset_close($extra = '') + { + return "\n".$extra; + } } // ------------------------------------------------------------------------ @@ -442,9 +487,12 @@ function form_fieldset_close($extra = '') * @param string * @return string */ -function form_close($extra = '') +if (! function_exists('form_close')) { - return "\n".$extra; + function form_close($extra = '') + { + return "\n".$extra; + } } // ------------------------------------------------------------------------ @@ -458,30 +506,33 @@ function form_close($extra = '') * @param string * @return string */ -function form_prep($str = '') +if (! function_exists('form_prep')) { - if ($str === '') + function form_prep($str = '') { - return ''; - } + if ($str === '') + { + return ''; + } - $temp = '__TEMP_AMPERSANDS__'; + $temp = '__TEMP_AMPERSANDS__'; - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - $str = htmlspecialchars($str); + $str = htmlspecialchars($str); - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - return $str; + return $str; + } } // ------------------------------------------------------------------------ @@ -496,37 +547,40 @@ function form_prep($str = '') * @param array * @return string */ -function parse_form_attributes($attributes, $default) +if (! function_exists('parse_form_attributes')) { - if (is_array($attributes)) + function parse_form_attributes($attributes, $default) { - foreach ($default as $key => $val) + if (is_array($attributes)) { - if (isset($attributes[$key])) + foreach ($default as $key => $val) { - $default[$key] = $attributes[$key]; - unset($attributes[$key]); + if (isset($attributes[$key])) + { + $default[$key] = $attributes[$key]; + unset($attributes[$key]); + } } - } - if (count($attributes) > 0) - { - $default = array_merge($default, $attributes); + if (count($attributes) > 0) + { + $default = array_merge($default, $attributes); + } } - } - $att = ''; - foreach ($default as $key => $val) - { - if ($key == 'value') + $att = ''; + foreach ($default as $key => $val) { - $val = form_prep($val); - } + if ($key == 'value') + { + $val = form_prep($val); + } - $att .= $key . '="' . $val . '" '; - } + $att .= $key . '="' . $val . '" '; + } - return $att; + return $att; + } } ?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 707d0e0f1e0ea922fbe38d8b43f1fb4e2ea001e5 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 18 Mar 2008 11:50:00 +0000 Subject: added form_button to form helper --- system/helpers/form_helper.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 7c3b16ff1..db41cb5cd 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -386,6 +386,33 @@ if (! function_exists('form_reset')) // ------------------------------------------------------------------------ +/** + * Form Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if (! function_exists('form_button')) +{ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + + if ( is_array($data) AND isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return "\n"; + } +} + +// ------------------------------------------------------------------------ + /** * Form Label Tag * -- cgit v1.2.3-24-g4f1b From 7327499064ae165468c7440f8571c3e570b58a0b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 5 May 2008 16:39:18 +0000 Subject: Added get_dir_file_info(), get_file_info(), and get_mime_by_extension() to the File Helper. Changed ( ! condition) into (! condition) within the code --- system/helpers/form_helper.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index db41cb5cd..10858339e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -48,7 +48,7 @@ if (! function_exists('form_open')) $form = '
'; } @@ -141,7 +141,7 @@ if (! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } @@ -164,7 +164,7 @@ if (! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -191,7 +191,7 @@ if (! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -216,9 +216,9 @@ if (! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if (! is_array($data) OR ! isset($data['value'])) { $val = $value; } @@ -248,7 +248,7 @@ if (! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - if ( ! is_array($selected)) + if (! is_array($selected)) { $selected = array($selected); } @@ -291,7 +291,7 @@ if (! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { @@ -332,7 +332,7 @@ if (! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') { - if ( ! is_array($data)) + if (! is_array($data)) { $data = array('name' => $data); } @@ -357,7 +357,7 @@ if (! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -378,7 +378,7 @@ if (! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -399,7 +399,7 @@ if (! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit'); if ( is_array($data) AND isset($data['content'])) { -- cgit v1.2.3-24-g4f1b From de7320bb78f02baa3b7cad3983d5b6d3a9c74f34 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 6 May 2008 13:51:02 +0000 Subject: Changed the radio() and checkbox() functions to default to not checked by default. --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 10858339e..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -289,7 +289,7 @@ if (! function_exists('form_dropdown')) */ if (! function_exists('form_checkbox')) { - function form_checkbox($data = '', $value = '', $checked = TRUE, $extra = '') + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); @@ -330,7 +330,7 @@ if (! function_exists('form_checkbox')) */ if (! function_exists('form_radio')) { - function form_radio($data = '', $value = '', $checked = TRUE, $extra = '') + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { if (! is_array($data)) { -- cgit v1.2.3-24-g4f1b From 5583e1aae64ff7e902136c4ba610d438dc2015d4 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 15:48:20 +0000 Subject: removed closing PHP tag from all framework files --- system/helpers/form_helper.php | 1 - 1 file changed, 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c9a6897ae..c91e5a5c7 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,3 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From c7deac9f2f9e43cedb18202542e8a46061df046e Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 16:27:41 +0000 Subject: Undoing change committed in r1115 --- system/helpers/form_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c91e5a5c7..c9a6897ae 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,3 +610,4 @@ if (! function_exists('parse_form_attributes')) } } +?> \ No newline at end of file -- cgit v1.2.3-24-g4f1b From a3ffbbb75ab9403941e4f810703313432b3993cc Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Sun, 11 May 2008 18:18:29 +0000 Subject: Removed closing PHP tags, replaced with a comment block identifying the end of the file --- system/helpers/form_helper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c9a6897ae..541ab844a 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,4 +610,6 @@ if (! function_exists('parse_form_attributes')) } } -?> \ No newline at end of file + +/* End of file form_helper.php */ +/* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0b59f270a432f8c7b6128981f0a39b4a2e2fbd34 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 13 May 2008 04:22:33 +0000 Subject: Some sweeping syntax changes for consistency: (! foo) changed to ( ! foo) || changed to OR changed newline standardization code in various places from preg_replace to str_replace --- system/helpers/form_helper.php | 70 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 541ab844a..c6aa0d2b4 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,4 +1,4 @@ -'; } @@ -137,11 +137,11 @@ if (! function_exists('form_hidden')) * @param string * @return string */ -if (! function_exists('form_input')) +if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); return "\n"; } @@ -160,11 +160,11 @@ if (! function_exists('form_input')) * @param string * @return string */ -if (! function_exists('form_password')) +if ( ! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -187,11 +187,11 @@ if (! function_exists('form_password')) * @param string * @return string */ -if (! function_exists('form_upload')) +if ( ! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -212,13 +212,13 @@ if (! function_exists('form_upload')) * @param string * @return string */ -if (! function_exists('form_textarea')) +if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { - $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if (! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } @@ -244,11 +244,11 @@ if (! function_exists('form_textarea')) * @param string * @return string */ -if (! function_exists('form_dropdown')) +if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') { - if (! is_array($selected)) + if ( ! is_array($selected)) { $selected = array($selected); } @@ -287,11 +287,11 @@ if (! function_exists('form_dropdown')) * @param string * @return string */ -if (! function_exists('form_checkbox')) +if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { - $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); if (is_array($data) AND array_key_exists('checked', $data)) { @@ -328,11 +328,11 @@ if (! function_exists('form_checkbox')) * @param string * @return string */ -if (! function_exists('form_radio')) +if ( ! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') { - if (! is_array($data)) + if ( ! is_array($data)) { $data = array('name' => $data); } @@ -353,11 +353,11 @@ if (! function_exists('form_radio')) * @param string * @return string */ -if (! function_exists('form_submit')) +if ( ! function_exists('form_submit')) { function form_submit($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -374,11 +374,11 @@ if (! function_exists('form_submit')) * @param string * @return string */ -if (! function_exists('form_reset')) +if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value); + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } @@ -395,11 +395,11 @@ if (! function_exists('form_reset')) * @param string * @return string */ -if (! function_exists('form_button')) +if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); if ( is_array($data) AND isset($data['content'])) { @@ -422,7 +422,7 @@ if (! function_exists('form_button')) * @param string Additional attributes * @return string */ -if (! function_exists('form_label')) +if ( ! function_exists('form_label')) { function form_label($label_text = '', $id = '', $attributes = array()) { @@ -460,7 +460,7 @@ if (! function_exists('form_label')) * @param string Additional attributes * @return string */ -if (! function_exists('form_fieldset')) +if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { @@ -497,7 +497,7 @@ if (! function_exists('form_fieldset')) * @param string * @return string */ -if (! function_exists('form_fieldset_close')) +if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { @@ -514,7 +514,7 @@ if (! function_exists('form_fieldset_close')) * @param string * @return string */ -if (! function_exists('form_close')) +if ( ! function_exists('form_close')) { function form_close($extra = '') { @@ -533,7 +533,7 @@ if (! function_exists('form_close')) * @param string * @return string */ -if (! function_exists('form_prep')) +if ( ! function_exists('form_prep')) { function form_prep($str = '') { @@ -574,7 +574,7 @@ if (! function_exists('form_prep')) * @param array * @return string */ -if (! function_exists('parse_form_attributes')) +if ( ! function_exists('parse_form_attributes')) { function parse_form_attributes($attributes, $default) { @@ -610,6 +610,6 @@ if (! function_exists('parse_form_attributes')) } } - -/* End of file form_helper.php */ + +/* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 1e6ab99c692bb0337559d3303143838dff37d638 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 6 Jun 2008 11:37:34 +0000 Subject: Form helper refactored to allow form_open() and form_fieldset() to accept arrays or strings as arguments. --- system/helpers/form_helper.php | 70 ++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 19 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c6aa0d2b4..cc08f4fe4 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -48,18 +48,7 @@ if ( ! function_exists('form_open')) $form = ' 0) - { - foreach ($attributes as $key => $val) - { - $form .= ' '.$key.'="'.$val.'"'; - } - } + $form .= _attributes_to_string($attributes, TRUE); $form .= '>'; @@ -467,13 +456,7 @@ if ( ! function_exists('form_fieldset')) $fieldset = " 0) - { - foreach ($attributes as $key => $val) - { - $fieldset .= ' '.$key.'="'.$val.'"'; - } - } + $fieldset .= _attributes_to_string($attributes, FALSE); $fieldset .= ">\n"; @@ -610,6 +593,55 @@ if ( ! function_exists('parse_form_attributes')) } } +// ------------------------------------------------------------------------ + +/** + * Attributes To String + * + * Helper function used by some of the form helpers + * + * @access private + * @param mixed + * @param bool + * @return string + */ +if ( ! function_exists('_attributes_to_string')) +{ + function _attributes_to_string($attributes, $formtag = FALSE) + { + if (is_string($attributes) AND strlen($attributes) > 0) + { + if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + return ' '.$attributes; + } + + if (is_object($attributes) AND count($attributes) > 0) + { + $attributes = (array)$attributes; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + $atts = ''; + + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + + return $atts; + } + } +} /* End of file form_helper.php */ /* Location: ./system/helpers/form_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From f7623aab9c9d9c0d0dae5911857cf8ba8d7a462c Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Fri, 6 Jun 2008 13:36:19 +0000 Subject: default to post method --- system/helpers/form_helper.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index cc08f4fe4..37afc2daf 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,7 +40,7 @@ */ if ( ! function_exists('form_open')) { - function form_open($action = '', $attributes = array(), $hidden = array()) + function form_open($action = '', $attributes = = 'method="post"', $hidden = array()) { $CI =& get_instance(); @@ -453,7 +453,6 @@ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) { - $fieldset = " Date: Fri, 6 Jun 2008 13:41:53 +0000 Subject: goofed. Fixed up. --- system/helpers/form_helper.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 37afc2daf..d250d76e8 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -40,10 +40,15 @@ */ if ( ! function_exists('form_open')) { - function form_open($action = '', $attributes = = 'method="post"', $hidden = array()) + function form_open($action = '', $attributes = '', $hidden = array()) { $CI =& get_instance(); + if ($attributes == '') + { + $attributes = 'method="post"'; + } + $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; $form = ' Date: Thu, 19 Jun 2008 07:46:22 +0000 Subject: removed maxlength and size as automatically added attributes in form helper --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index d250d76e8..5b28d3de8 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -135,7 +135,7 @@ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50'); + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); return "\n"; } -- cgit v1.2.3-24-g4f1b From c507418db9a35ef11965cb9226e6f23f3b41b195 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 21 Jul 2008 11:58:56 +0000 Subject: Removed added newlines ("\n") from most form and html helper functions. --- system/helpers/form_helper.php | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5b28d3de8..21b7df42f 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -111,6 +111,7 @@ if ( ! function_exists('form_hidden')) } $form = ''; + foreach ($name as $name => $value) { $form .= ''; @@ -137,7 +138,7 @@ if ( ! function_exists('form_input')) { $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return ""; } } @@ -222,7 +223,7 @@ if ( ! function_exists('form_textarea')) unset($data['value']); // textareas don't use the value attribute } - return "\n"; + return ""; } } @@ -302,11 +303,15 @@ if ( ! function_exists('form_checkbox')) } if ($checked == TRUE) + { $defaults['checked'] = 'checked'; + } else + { unset($defaults['checked']); + } - return "\n"; + return ""; } } @@ -353,7 +358,7 @@ if ( ! function_exists('form_submit')) { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return ""; } } @@ -374,7 +379,7 @@ if ( ! function_exists('form_reset')) { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return "\n"; + return ""; } } @@ -401,7 +406,7 @@ if ( ! function_exists('form_button')) unset($data['content']); // content is not an attribute } - return "\n"; + return ""; } } @@ -486,7 +491,7 @@ if ( ! function_exists('form_fieldset_close')) { function form_fieldset_close($extra = '') { - return "\n".$extra; + return "".$extra; } } @@ -503,7 +508,7 @@ if ( ! function_exists('form_close')) { function form_close($extra = '') { - return "\n".$extra; + return "".$extra; } } -- cgit v1.2.3-24-g4f1b From f388511b8596558ef560eca6a99bd435805e2d59 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 12 Aug 2008 05:32:25 +0000 Subject: Added newline character in between hidden fields --- system/helpers/form_helper.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 21b7df42f..0ad57d532 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -114,6 +114,7 @@ if ( ! function_exists('form_hidden')) foreach ($name as $name => $value) { + $form .= "\n"; $form .= ''; } -- cgit v1.2.3-24-g4f1b From 993925b47a0bfb08e79961c47bcc3d247a03a5dd Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 21 Aug 2008 12:43:31 +0000 Subject: whitespace fixes a minor re-ordering of the changelog --- system/helpers/form_helper.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0ad57d532..0c74ac0ff 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -53,7 +53,7 @@ if ( ! function_exists('form_open')) $form = '
(( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } - else + else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute @@ -466,7 +466,7 @@ if ( ! function_exists('form_fieldset')) { $fieldset = " 0) -- cgit v1.2.3-24-g4f1b From 43e0fbb650d05466cd2568b8a2cc1c38849a6b52 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 19:22:31 +0000 Subject: Added some new functions that work with the new form validation class --- system/helpers/form_helper.php | 335 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 321 insertions(+), 14 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0c74ac0ff..a96adb97d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -53,7 +53,7 @@ if ( ! function_exists('form_open')) $form = ' 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -214,17 +214,17 @@ if ( ! function_exists('form_textarea')) { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } - else + else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - return ""; + return ""; } } @@ -248,6 +248,16 @@ if ( ! function_exists('form_dropdown')) { $selected = array($selected); } + + // If no selected state was submitted we will attempt to set it automatically + if (count($selected) === 0) + { + // If the form name appears in the $_POST array we have a winner! + if (isset($_POST[$name])) + { + $selected = array($_POST[$name]); + } + } if ($extra != '') $extra = ' '.$extra; @@ -312,7 +322,7 @@ if ( ! function_exists('form_checkbox')) unset($defaults['checked']); } - return ""; + return ""; } } @@ -359,7 +369,7 @@ if ( ! function_exists('form_submit')) { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -380,7 +390,7 @@ if ( ! function_exists('form_reset')) { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -407,7 +417,7 @@ if ( ! function_exists('form_button')) unset($data['content']); // content is not an attribute } - return ""; + return ""; } } @@ -466,7 +476,7 @@ if ( ! function_exists('form_fieldset')) { $fieldset = " $val) + { + $str[$key] = form_prep($val); + } + + return $str; + } + if ($str === '') { return ''; @@ -552,7 +573,256 @@ if ( ! function_exists('form_prep')) return $str; } } + +// ------------------------------------------------------------------------ + +/** + * Form Value + * + * Grabs a value from the POST array for the specified field so you can + * re-populate an input field or textarea. If Form Validation + * is active it retrieves the info from the validation class + * + * @access public + * @param string + * @return mixed + */ +if ( ! function_exists('set_value')) +{ + function set_value($field = '', $default = '') + { + if (FALSE === ($OBJ =& _get_validation_object())) + { + if ( ! isset($_POST[$field])) + { + return $default; + } + + return $_POST[$field]; + } + + return $OBJ->set_value($field, $default); + } +} + +// ------------------------------------------------------------------------ + +/** + * Set Select + * + * Let's you set the selected value of a '; } - + return $form; } } - + // ------------------------------------------------------------------------ /** @@ -132,7 +132,7 @@ if ( ! function_exists('form_hidden')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_input')) { function form_input($data = '', $value = '', $extra = '') @@ -142,7 +142,7 @@ if ( ! function_exists('form_input')) return ""; } } - + // ------------------------------------------------------------------------ /** @@ -155,7 +155,7 @@ if ( ! function_exists('form_input')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_password')) { function form_password($data = '', $value = '', $extra = '') @@ -169,7 +169,7 @@ if ( ! function_exists('form_password')) return form_input($data, $value, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -182,7 +182,7 @@ if ( ! function_exists('form_password')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_upload')) { function form_upload($data = '', $value = '', $extra = '') @@ -196,7 +196,7 @@ if ( ! function_exists('form_upload')) return form_input($data, $value, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -207,13 +207,13 @@ if ( ! function_exists('form_upload')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_textarea')) { function form_textarea($data = '', $value = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; @@ -223,11 +223,11 @@ if ( ! function_exists('form_textarea')) $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - + return ""; } } - + // ------------------------------------------------------------------------ /** @@ -239,7 +239,7 @@ if ( ! function_exists('form_textarea')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_dropdown')) { function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') @@ -248,7 +248,7 @@ if ( ! function_exists('form_dropdown')) { $selected = array($selected); } - + // If no selected state was submitted we will attempt to set it automatically if (count($selected) === 0) { @@ -269,18 +269,18 @@ if ( ! function_exists('form_dropdown')) { $key = (string) $key; $val = (string) $val; - + $sel = (in_array($key, $selected))?' selected="selected"':''; - + $form .= '\n"; } $form .= ''; - + return $form; } } - + // ------------------------------------------------------------------------ /** @@ -292,17 +292,17 @@ if ( ! function_exists('form_dropdown')) * @param bool * @param string * @return string - */ + */ if ( ! function_exists('form_checkbox')) { function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') { $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - + if (is_array($data) AND array_key_exists('checked', $data)) { $checked = $data['checked']; - + if ($checked == FALSE) { unset($data['checked']); @@ -312,7 +312,7 @@ if ( ! function_exists('form_checkbox')) $data['checked'] = 'checked'; } } - + if ($checked == TRUE) { $defaults['checked'] = 'checked'; @@ -325,7 +325,7 @@ if ( ! function_exists('form_checkbox')) return ""; } } - + // ------------------------------------------------------------------------ /** @@ -337,7 +337,7 @@ if ( ! function_exists('form_checkbox')) * @param bool * @param string * @return string - */ + */ if ( ! function_exists('form_radio')) { function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') @@ -351,7 +351,7 @@ if ( ! function_exists('form_radio')) return form_checkbox($data, $value, $checked, $extra); } } - + // ------------------------------------------------------------------------ /** @@ -383,7 +383,7 @@ if ( ! function_exists('form_submit')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_reset')) { function form_reset($data = '', $value = '', $extra = '') @@ -404,19 +404,19 @@ if ( ! function_exists('form_reset')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); - + if ( is_array($data) AND isset($data['content'])) { $content = $data['content']; unset($data['content']); // content is not an attribute } - + return ""; } } @@ -431,19 +431,19 @@ if ( ! function_exists('form_button')) * @param string The id the label applies to * @param string Additional attributes * @return string - */ + */ if ( ! function_exists('form_label')) { function form_label($label_text = '', $id = '', $attributes = array()) { $label = ' 0) { foreach ($attributes as $key => $val) @@ -469,7 +469,7 @@ if ( ! function_exists('form_label')) * @param string The legend text * @param string Additional attributes * @return string - */ + */ if ( ! function_exists('form_fieldset')) { function form_fieldset($legend_text = '', $attributes = array()) @@ -477,9 +477,9 @@ if ( ! function_exists('form_fieldset')) $fieldset = "".$extra; } } - + // ------------------------------------------------------------------------ /** @@ -514,7 +514,7 @@ if ( ! function_exists('form_fieldset_close')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('form_close')) { function form_close($extra = '') @@ -522,7 +522,7 @@ if ( ! function_exists('form_close')) return "".$extra; } } - + // ------------------------------------------------------------------------ /** @@ -533,7 +533,7 @@ if ( ! function_exists('form_close')) * @access public * @param string * @return string - */ + */ if ( ! function_exists('form_prep')) { function form_prep($str = '') @@ -545,17 +545,17 @@ if ( ! function_exists('form_prep')) { $str[$key] = form_prep($val); } - + return $str; } - + if ($str === '') { return ''; } $temp = '__TEMP_AMPERSANDS__'; - + // Replace entities to temporary markers so that // htmlspecialchars won't mess them up $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); @@ -564,13 +564,13 @@ if ( ! function_exists('form_prep')) $str = htmlspecialchars($str); // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - + $str = str_replace(array("'", '"'), array("'", """), $str); + // Decode the temp markers back to entities $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; } } @@ -586,7 +586,7 @@ if ( ! function_exists('form_prep')) * @access public * @param string * @return mixed - */ + */ if ( ! function_exists('set_value')) { function set_value($field = '', $default = '') @@ -597,10 +597,10 @@ if ( ! function_exists('set_value')) { return $default; } - + return $_POST[$field]; } - + return $OBJ->set_value($field, $default); } } @@ -618,7 +618,7 @@ if ( ! function_exists('set_value')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_select')) { function set_select($field = '', $value = '', $default = FALSE) @@ -635,9 +635,9 @@ if ( ! function_exists('set_select')) } return ''; } - + $field = $_POST[$field]; - + if (is_array($field)) { if ( ! in_array($value, $field)) @@ -652,10 +652,10 @@ if ( ! function_exists('set_select')) return ''; } } - + return ' selected="selected"'; } - + return $OBJ->set_select($field, $value, $default); } } @@ -673,7 +673,7 @@ if ( ! function_exists('set_select')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_checkbox')) { function set_checkbox($field = '', $value = '', $default = FALSE) @@ -690,7 +690,7 @@ if ( ! function_exists('set_checkbox')) } return ''; } - + $field = $_POST[$field]; if (is_array($field)) @@ -707,10 +707,10 @@ if ( ! function_exists('set_checkbox')) return ''; } } - + return ' checked="checked"'; } - + return $OBJ->set_checkbox($field, $value, $default); } } @@ -728,7 +728,7 @@ if ( ! function_exists('set_checkbox')) * @param string * @param bool * @return string - */ + */ if ( ! function_exists('set_radio')) { function set_radio($field = '', $value = '', $default = FALSE) @@ -745,7 +745,7 @@ if ( ! function_exists('set_radio')) } return ''; } - + $field = $_POST[$field]; if (is_array($field)) @@ -762,10 +762,10 @@ if ( ! function_exists('set_radio')) return ''; } } - + return ' checked="checked"'; } - + return $OBJ->set_radio($field, $value, $default); } } @@ -783,7 +783,7 @@ if ( ! function_exists('set_radio')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('form_error')) { function form_error($field = '', $prefix = '', $suffix = '') @@ -792,7 +792,7 @@ if ( ! function_exists('form_error')) { return ''; } - + return $OBJ->error($field, $prefix, $suffix); } } @@ -809,7 +809,7 @@ if ( ! function_exists('form_error')) * @param string * @param string * @return string - */ + */ if ( ! function_exists('validation_errors')) { function validation_errors($prefix = '', $suffix = '') @@ -818,7 +818,7 @@ if ( ! function_exists('validation_errors')) { return ''; } - + return $OBJ->error_string($prefix, $suffix); } } @@ -834,7 +834,7 @@ if ( ! function_exists('validation_errors')) * @param array * @param array * @return string - */ + */ if ( ! function_exists('_parse_form_attributes')) { function _parse_form_attributes($attributes, $default) @@ -849,21 +849,22 @@ if ( ! function_exists('_parse_form_attributes')) unset($attributes[$key]); } } - + if (count($attributes) > 0) - { + { $default = array_merge($default, $attributes); } } - + $att = ''; + foreach ($default as $key => $val) { if ($key == 'value') { $val = form_prep($val); } - + $att .= $key . '="' . $val . '" '; } @@ -882,43 +883,43 @@ if ( ! function_exists('_parse_form_attributes')) * @param mixed * @param bool * @return string - */ + */ if ( ! function_exists('_attributes_to_string')) { function _attributes_to_string($attributes, $formtag = FALSE) { - if (is_string($attributes) AND strlen($attributes) > 0) - { - if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) - { - $attributes .= ' method="post"'; - } - - return ' '.$attributes; - } - - if (is_object($attributes) AND count($attributes) > 0) - { - $attributes = (array)$attributes; - } - - if (is_array($attributes) AND count($attributes) > 0) - { - $atts = ''; - - if ( ! isset($attributes['method']) AND $formtag === TRUE) - { - $atts .= ' method="post"'; - } + if (is_string($attributes) AND strlen($attributes) > 0) + { + if ($formtag == TRUE AND strpos($attributes, 'method=') === FALSE) + { + $attributes .= ' method="post"'; + } + + return ' '.$attributes; + } - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - - return $atts; - } - } + if (is_object($attributes) AND count($attributes) > 0) + { + $attributes = (array)$attributes; + } + + if (is_array($attributes) AND count($attributes) > 0) + { + $atts = ''; + + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + + return $atts; + } + } } // ------------------------------------------------------------------------ @@ -931,28 +932,28 @@ if ( ! function_exists('_attributes_to_string')) * * @access private * @return mixed - */ + */ if ( ! function_exists('_get_validation_object')) -{ +{ function &_get_validation_object() { $CI =& get_instance(); - + // We set this as a variable since we're returning by reference $return = FALSE; - + if ( ! isset($CI->load->_ci_classes) OR ! isset($CI->load->_ci_classes['form_validation'])) { return $return; } - + $object = $CI->load->_ci_classes['form_validation']; - + if ( ! isset($CI->$object) OR ! is_object($CI->$object)) { return $return; } - + return $CI->$object; } } -- cgit v1.2.3-24-g4f1b From 69db8efaffadfc93ff0eec3a9733793e8b358dfb Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 25 Sep 2008 13:04:12 +0000 Subject: Fixed incorrect parenthesis in form_open() function. (#5135) A few doc typo fixes --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index fc2592241..a45faf631 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -57,7 +57,7 @@ if ( ! function_exists('form_open')) $form .= '>'; - if (is_array($hidden) AND count($hidden > 0)) + if (is_array($hidden) AND count($hidden) > 0) { $form .= form_hidden($hidden); } -- cgit v1.2.3-24-g4f1b From 862545a5adb76df0393022b3506eb203c9a543d7 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 20 Oct 2008 20:39:14 +0000 Subject: Added form_prep() call to set_value() --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index a45faf631..109d8c17b 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -598,10 +598,10 @@ if ( ! function_exists('set_value')) return $default; } - return $_POST[$field]; + return form_prep($_POST[$field]); } - return $OBJ->set_value($field, $default); + return form_prep($OBJ->set_value($field, $default)); } } -- cgit v1.2.3-24-g4f1b From 2067d1a727e7eb5e5ffb40e967f3d1fc4c8a41b2 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 13 Nov 2008 22:59:24 +0000 Subject: Changing EOL style to LF --- system/helpers/form_helper.php | 1924 ++++++++++++++++++++-------------------- 1 file changed, 962 insertions(+), 962 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 109d8c17b..c002c6fc0 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -1,963 +1,963 @@ -config->site_url($action) : $action; - - $form = '
0) - { - $form .= form_hidden($hidden); - } - - return $form; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Declaration - Multipart type - * - * Creates the opening portion of the form, but with "multipart/form-data". - * - * @access public - * @param string the URI segments of the form destination - * @param array a key/value pair of attributes - * @param array a key/value pair hidden data - * @return string - */ -if ( ! function_exists('form_open_multipart')) -{ - function form_open_multipart($action, $attributes = array(), $hidden = array()) - { - $attributes['enctype'] = 'multipart/form-data'; - return form_open($action, $attributes, $hidden); - } -} - -// ------------------------------------------------------------------------ - -/** - * Hidden Input Field - * - * Generates hidden fields. You can pass a simple key/value string or an associative - * array with multiple values. - * - * @access public - * @param mixed - * @param string - * @return string - */ -if ( ! function_exists('form_hidden')) -{ - function form_hidden($name, $value = '') - { - if ( ! is_array($name)) - { - return ''; - } - - $form = ''; - - foreach ($name as $name => $value) - { - $form .= "\n"; - $form .= ''; - } - - return $form; - } -} - -// ------------------------------------------------------------------------ - -/** - * Text Input Field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_input')) -{ - function form_input($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Password Field - * - * Identical to the input function but adds the "password" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_password')) -{ - function form_password($data = '', $value = '', $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'password'; - return form_input($data, $value, $extra); - } -} - -// ------------------------------------------------------------------------ - -/** - * Upload Field - * - * Identical to the input function but adds the "file" type - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_upload')) -{ - function form_upload($data = '', $value = '', $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'file'; - return form_input($data, $value, $extra); - } -} - -// ------------------------------------------------------------------------ - -/** - * Textarea field - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_textarea')) -{ - function form_textarea($data = '', $value = '', $extra = '') - { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - - if ( ! is_array($data) OR ! isset($data['value'])) - { - $val = $value; - } - else - { - $val = $data['value']; - unset($data['value']); // textareas don't use the value attribute - } - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Drop-down Menu - * - * @access public - * @param string - * @param array - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_dropdown')) -{ - function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') - { - if ( ! is_array($selected)) - { - $selected = array($selected); - } - - // If no selected state was submitted we will attempt to set it automatically - if (count($selected) === 0) - { - // If the form name appears in the $_POST array we have a winner! - if (isset($_POST[$name])) - { - $selected = array($_POST[$name]); - } - } - - if ($extra != '') $extra = ' '.$extra; - - $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; - - $form = ''; - - return $form; - } -} - -// ------------------------------------------------------------------------ - -/** - * Checkbox Field - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -if ( ! function_exists('form_checkbox')) -{ - function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') - { - $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - if (is_array($data) AND array_key_exists('checked', $data)) - { - $checked = $data['checked']; - - if ($checked == FALSE) - { - unset($data['checked']); - } - else - { - $data['checked'] = 'checked'; - } - } - - if ($checked == TRUE) - { - $defaults['checked'] = 'checked'; - } - else - { - unset($defaults['checked']); - } - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Radio Button - * - * @access public - * @param mixed - * @param string - * @param bool - * @param string - * @return string - */ -if ( ! function_exists('form_radio')) -{ - function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') - { - if ( ! is_array($data)) - { - $data = array('name' => $data); - } - - $data['type'] = 'radio'; - return form_checkbox($data, $value, $checked, $extra); - } -} - -// ------------------------------------------------------------------------ - -/** - * Submit Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_submit')) -{ - function form_submit($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Reset Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_reset')) -{ - function form_reset($data = '', $value = '', $extra = '') - { - $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Button - * - * @access public - * @param mixed - * @param string - * @param string - * @return string - */ -if ( ! function_exists('form_button')) -{ - function form_button($data = '', $content = '', $extra = '') - { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); - - if ( is_array($data) AND isset($data['content'])) - { - $content = $data['content']; - unset($data['content']); // content is not an attribute - } - - return ""; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Label Tag - * - * @access public - * @param string The text to appear onscreen - * @param string The id the label applies to - * @param string Additional attributes - * @return string - */ -if ( ! function_exists('form_label')) -{ - function form_label($label_text = '', $id = '', $attributes = array()) - { - - $label = ' 0) - { - foreach ($attributes as $key => $val) - { - $label .= ' '.$key.'="'.$val.'"'; - } - } - - $label .= ">$label_text"; - - return $label; - } -} - -// ------------------------------------------------------------------------ -/** - * Fieldset Tag - * - * Used to produce
text. To close fieldset - * use form_fieldset_close() - * - * @access public - * @param string The legend text - * @param string Additional attributes - * @return string - */ -if ( ! function_exists('form_fieldset')) -{ - function form_fieldset($legend_text = '', $attributes = array()) - { - $fieldset = "".$extra; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Close Tag - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('form_close')) -{ - function form_close($extra = '') - { - return "".$extra; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Prep - * - * Formats text so that it can be safely placed in a form field in the event it has HTML tags. - * - * @access public - * @param string - * @return string - */ -if ( ! function_exists('form_prep')) -{ - function form_prep($str = '') - { - // if the field name is an array we do this recursively - if (is_array($str)) - { - foreach ($str as $key => $val) - { - $str[$key] = form_prep($val); - } - - return $str; - } - - if ($str === '') - { - return ''; - } - - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - - $str = htmlspecialchars($str); - - // In case htmlspecialchars misses these. - $str = str_replace(array("'", '"'), array("'", """), $str); - - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - - return $str; - } -} - -// ------------------------------------------------------------------------ - -/** - * Form Value - * - * Grabs a value from the POST array for the specified field so you can - * re-populate an input field or textarea. If Form Validation - * is active it retrieves the info from the validation class - * - * @access public - * @param string - * @return mixed - */ -if ( ! function_exists('set_value')) -{ - function set_value($field = '', $default = '') - { - if (FALSE === ($OBJ =& _get_validation_object())) - { - if ( ! isset($_POST[$field])) - { - return $default; - } - - return form_prep($_POST[$field]); - } - - return form_prep($OBJ->set_value($field, $default)); - } -} - -// ------------------------------------------------------------------------ - -/** - * Set Select - * - * Let's you set the selected value of a '; + } + + $form = ''; + + foreach ($name as $name => $value) + { + $form .= "\n"; + $form .= ''; + } + + return $form; + } +} + +// ------------------------------------------------------------------------ + +/** + * Text Input Field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_input')) +{ + function form_input($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Password Field + * + * Identical to the input function but adds the "password" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_password')) +{ + function form_password($data = '', $value = '', $extra = '') + { + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'password'; + return form_input($data, $value, $extra); + } +} + +// ------------------------------------------------------------------------ + +/** + * Upload Field + * + * Identical to the input function but adds the "file" type + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_upload')) +{ + function form_upload($data = '', $value = '', $extra = '') + { + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'file'; + return form_input($data, $value, $extra); + } +} + +// ------------------------------------------------------------------------ + +/** + * Textarea field + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_textarea')) +{ + function form_textarea($data = '', $value = '', $extra = '') + { + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); + + if ( ! is_array($data) OR ! isset($data['value'])) + { + $val = $value; + } + else + { + $val = $data['value']; + unset($data['value']); // textareas don't use the value attribute + } + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Drop-down Menu + * + * @access public + * @param string + * @param array + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_dropdown')) +{ + function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '') + { + if ( ! is_array($selected)) + { + $selected = array($selected); + } + + // If no selected state was submitted we will attempt to set it automatically + if (count($selected) === 0) + { + // If the form name appears in the $_POST array we have a winner! + if (isset($_POST[$name])) + { + $selected = array($_POST[$name]); + } + } + + if ($extra != '') $extra = ' '.$extra; + + $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; + + $form = ''; + + return $form; + } +} + +// ------------------------------------------------------------------------ + +/** + * Checkbox Field + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +if ( ! function_exists('form_checkbox')) +{ + function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') + { + $defaults = array('type' => 'checkbox', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + if (is_array($data) AND array_key_exists('checked', $data)) + { + $checked = $data['checked']; + + if ($checked == FALSE) + { + unset($data['checked']); + } + else + { + $data['checked'] = 'checked'; + } + } + + if ($checked == TRUE) + { + $defaults['checked'] = 'checked'; + } + else + { + unset($defaults['checked']); + } + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Radio Button + * + * @access public + * @param mixed + * @param string + * @param bool + * @param string + * @return string + */ +if ( ! function_exists('form_radio')) +{ + function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') + { + if ( ! is_array($data)) + { + $data = array('name' => $data); + } + + $data['type'] = 'radio'; + return form_checkbox($data, $value, $checked, $extra); + } +} + +// ------------------------------------------------------------------------ + +/** + * Submit Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_submit')) +{ + function form_submit($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Reset Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_reset')) +{ + function form_reset($data = '', $value = '', $extra = '') + { + $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Form Button + * + * @access public + * @param mixed + * @param string + * @param string + * @return string + */ +if ( ! function_exists('form_button')) +{ + function form_button($data = '', $content = '', $extra = '') + { + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + + if ( is_array($data) AND isset($data['content'])) + { + $content = $data['content']; + unset($data['content']); // content is not an attribute + } + + return ""; + } +} + +// ------------------------------------------------------------------------ + +/** + * Form Label Tag + * + * @access public + * @param string The text to appear onscreen + * @param string The id the label applies to + * @param string Additional attributes + * @return string + */ +if ( ! function_exists('form_label')) +{ + function form_label($label_text = '', $id = '', $attributes = array()) + { + + $label = ' 0) + { + foreach ($attributes as $key => $val) + { + $label .= ' '.$key.'="'.$val.'"'; + } + } + + $label .= ">$label_text"; + + return $label; + } +} + +// ------------------------------------------------------------------------ +/** + * Fieldset Tag + * + * Used to produce
text. To close fieldset + * use form_fieldset_close() + * + * @access public + * @param string The legend text + * @param string Additional attributes + * @return string + */ +if ( ! function_exists('form_fieldset')) +{ + function form_fieldset($legend_text = '', $attributes = array()) + { + $fieldset = "".$extra; + } +} + +// ------------------------------------------------------------------------ + +/** + * Form Close Tag + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('form_close')) +{ + function form_close($extra = '') + { + return "".$extra; + } +} + +// ------------------------------------------------------------------------ + +/** + * Form Prep + * + * Formats text so that it can be safely placed in a form field in the event it has HTML tags. + * + * @access public + * @param string + * @return string + */ +if ( ! function_exists('form_prep')) +{ + function form_prep($str = '') + { + // if the field name is an array we do this recursively + if (is_array($str)) + { + foreach ($str as $key => $val) + { + $str[$key] = form_prep($val); + } + + return $str; + } + + if ($str === '') + { + return ''; + } + + $temp = '__TEMP_AMPERSANDS__'; + + // Replace entities to temporary markers so that + // htmlspecialchars won't mess them up + $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); + $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); + + $str = htmlspecialchars($str); + + // In case htmlspecialchars misses these. + $str = str_replace(array("'", '"'), array("'", """), $str); + + // Decode the temp markers back to entities + $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); + $str = preg_replace("/$temp(\w+);/","&\\1;",$str); + + return $str; + } +} + +// ------------------------------------------------------------------------ + +/** + * Form Value + * + * Grabs a value from the POST array for the specified field so you can + * re-populate an input field or textarea. If Form Validation + * is active it retrieves the info from the validation class + * + * @access public + * @param string + * @return mixed + */ +if ( ! function_exists('set_value')) +{ + function set_value($field = '', $default = '') + { + if (FALSE === ($OBJ =& _get_validation_object())) + { + if ( ! isset($_POST[$field])) + { + return $default; + } + + return form_prep($_POST[$field]); + } + + return form_prep($OBJ->set_value($field, $default)); + } +} + +// ------------------------------------------------------------------------ + +/** + * Set Select + * + * Let's you set the selected value of a '; -- cgit v1.2.3-24-g4f1b From 86a840cc46ec3f0b8a83938e665a52e625b9f3c7 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 5 Feb 2009 17:31:58 +0000 Subject: wrong var fix --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 01d0ea76d..8cae91a41 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -275,7 +275,7 @@ if ( ! function_exists('form_dropdown')) foreach ($val as $optgroup_key => $optgroup_val) { - $sel = (in_array($key, $selected)) ? ' selected="selected"' : ''; + $sel = (in_array($optgroup_key, $selected)) ? ' selected="selected"' : ''; $form .= '\n"; } -- cgit v1.2.3-24-g4f1b From 904094a177488edeacbe8e184d788c286c3e3d9f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 10 Feb 2009 14:00:34 +0000 Subject: Changed the default "type" of form_button() to "button" from "submit" in the form helper. --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 8cae91a41..4a62cdb5e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -424,7 +424,7 @@ if ( ! function_exists('form_button')) { function form_button($data = '', $content = '', $extra = '') { - $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'submit'); + $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'type' => 'button'); if ( is_array($data) AND isset($data['content'])) { -- cgit v1.2.3-24-g4f1b From 28e5c8fc0ed79017a67b896613698e98fa7da8b3 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Mon, 9 Mar 2009 22:36:48 +0000 Subject: Fixed a bug that was not setting the default checkbox/radio/pull-down value correctly --- system/helpers/form_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 4a62cdb5e..05616f707 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -644,7 +644,7 @@ if ( ! function_exists('set_select')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' selected="selected"'; } @@ -699,7 +699,7 @@ if ( ! function_exists('set_checkbox')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } @@ -754,7 +754,7 @@ if ( ! function_exists('set_radio')) { if ( ! isset($_POST[$field])) { - if (count($_POST) === 0) + if (count($_POST) === 0 AND $default == TRUE) { return ' checked="checked"'; } -- cgit v1.2.3-24-g4f1b From 57fe41072c9d97d3cba2cd5faef529ac94571bfb Mon Sep 17 00:00:00 2001 From: Robin Sowell Date: Thu, 26 Mar 2009 18:58:46 +0000 Subject: Modified form_hidden() to accept multi-dimensional arrays. --- system/helpers/form_helper.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 05616f707..0173340c5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -103,19 +103,35 @@ if ( ! function_exists('form_open_multipart')) */ if ( ! function_exists('form_hidden')) { - function form_hidden($name, $value = '') + function form_hidden($name, $value = '', $recursing = FALSE) { - if ( ! is_array($name)) + static $form; + + if ($recursing === FALSE) { - return ''; + $form = "\n"; } - $form = ''; + if (is_array($name)) + { + foreach ($name as $key => $val) + { + form_hidden($key, $val, TRUE); + } + return $form; + } - foreach ($name as $name => $value) + if ( ! is_array($value)) + { + $form .= ''."\n"; + } + else { - $form .= "\n"; - $form .= ''; + foreach ($value as $k => $v) + { + $k = (is_int($k)) ? '' : $k; + form_hidden($name.'['.$k.']', $v, TRUE); + } } return $form; @@ -264,7 +280,7 @@ if ( ! function_exists('form_dropdown')) $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; $form = '"; + return ""; } } -- cgit v1.2.3-24-g4f1b From 8c5299640fed112bb86e7a3930432bd084e86dad Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 10 Jul 2009 19:05:08 +0000 Subject: removed entity protection from form_prep() so as to preserve the user's input when called back into a form element --- system/helpers/form_helper.php | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index bdc87b86f..987ff18e2 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -610,22 +610,11 @@ if ( ! function_exists('form_prep')) return ''; } - $temp = '__TEMP_AMPERSANDS__'; - - // Replace entities to temporary markers so that - // htmlspecialchars won't mess them up - $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str); - $str = preg_replace("/&(\w+);/", "$temp\\1;", $str); - $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("'", """), $str); - // Decode the temp markers back to entities - $str = preg_replace("/$temp(\d+);/","&#\\1;",$str); - $str = preg_replace("/$temp(\w+);/","&\\1;",$str); - return $str; } } -- cgit v1.2.3-24-g4f1b From 01a9b107cab449d1ce24746612e9cf7074e6608d Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 17 Jul 2009 18:30:36 +0000 Subject: modified Form Helper so that form_prep() keeps track of strings it's already processed, to prevent encoding and prep from occurring more than once --- system/helpers/form_helper.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 987ff18e2..4c229ae9f 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -123,7 +123,7 @@ if ( ! function_exists('form_hidden')) if ( ! is_array($value)) { - $form .= ''."\n"; + $form .= ''."\n"; } else { @@ -239,8 +239,9 @@ if ( ! function_exists('form_textarea')) $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - - return ""; + + $name = (is_array($data)) ? $data['name'] : $data; + return ""; } } @@ -264,7 +265,7 @@ if (! function_exists('form_multiselect')) { $extra .= ' multiple="multiple"'; } - + return form_dropdown($name, $options, $selected, $extra); } } @@ -592,8 +593,10 @@ if ( ! function_exists('form_close')) */ if ( ! function_exists('form_prep')) { - function form_prep($str = '') + function form_prep($str = '', $field_name = '') { + static $prepped_fields = array(); + // if the field name is an array we do this recursively if (is_array($str)) { @@ -610,11 +613,21 @@ if ( ! function_exists('form_prep')) return ''; } + if (isset($prepped_fields[$field_name])) + { + return $prepped_fields[$field_name]; + } + $str = htmlspecialchars($str); // In case htmlspecialchars misses these. $str = str_replace(array("'", '"'), array("'", """), $str); + if ($field_name != '') + { + $prepped_fields[$field_name] = $str; + } + return $str; } } @@ -643,10 +656,10 @@ if ( ! function_exists('set_value')) return $default; } - return form_prep($_POST[$field]); + return form_prep($_POST[$field], $field); } - return form_prep($OBJ->set_value($field, $default)); + return form_prep($OBJ->set_value($field, $default), $field); } } @@ -902,12 +915,12 @@ if ( ! function_exists('_parse_form_attributes')) } $att = ''; - + foreach ($default as $key => $val) { if ($key == 'value') { - $val = form_prep($val); + $val = form_prep($val, $default['name']); } $att .= $key . '="' . $val . '" '; -- cgit v1.2.3-24-g4f1b From 3eb9faceb9fedb0fa50a2b2d1fc4952c2652af70 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 17 Jul 2009 20:25:13 +0000 Subject: modification to form_prep() solution. A bandaid really, to return the $str if the field has already been prepped --- system/helpers/form_helper.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 4c229ae9f..c5e977a40 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -613,9 +613,13 @@ if ( ! function_exists('form_prep')) return ''; } + // we've already prepped a field with this name + // @todo need to figure out a way to namespace this so + // that we know the *exact* field and not just one with + // the same name if (isset($prepped_fields[$field_name])) { - return $prepped_fields[$field_name]; + return $str; } $str = htmlspecialchars($str); -- cgit v1.2.3-24-g4f1b From 928158bf3a308330ab6518ff0d149d4585d7f38f Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 08:20:58 +0000 Subject: adding accept-charset to form_open() --- system/helpers/form_helper.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c5e977a40..2fd4807fc 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,9 +44,30 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); + $charset = strtolower($CI->config->item('charset')); + if ($attributes == '') { - $attributes = 'method="post"'; + $attributes = 'method="post" accept-charset="'.$charset.'"'; + } + else + { + if ( is_string($attributes) ) + { + if(strpos('accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.$charset.'"'; + } + } + else + { + $attributes = (array) $attributes; + + if(!in_array('accept-charset', $attributes)) + { + $attributes['accept-charset'] = $charset; + } + } } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; -- cgit v1.2.3-24-g4f1b From f673a87ad9530a2982caef0bd5a53983d6b06a63 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Wed, 16 Sep 2009 09:35:03 +0000 Subject: --- system/helpers/form_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 2fd4807fc..5917d1016 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -52,7 +52,7 @@ if ( ! function_exists('form_open')) } else { - if ( is_string($attributes) ) + if ( is_string($attributes)) { if(strpos('accept-charset=') === FALSE) { @@ -63,7 +63,7 @@ if ( ! function_exists('form_open')) { $attributes = (array) $attributes; - if(!in_array('accept-charset', $attributes)) + if ( ! in_array('accept-charset', $attributes)) { $attributes['accept-charset'] = $charset; } -- cgit v1.2.3-24-g4f1b From 3241d73d55649893cea7c55d1d24b2981088b0d1 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 17 Sep 2009 12:17:45 +0000 Subject: modified the way accept-charset is added --- system/helpers/form_helper.php | 54 +++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 32 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5917d1016..02e2edd3e 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -44,30 +44,9 @@ if ( ! function_exists('form_open')) { $CI =& get_instance(); - $charset = strtolower($CI->config->item('charset')); - if ($attributes == '') { - $attributes = 'method="post" accept-charset="'.$charset.'"'; - } - else - { - if ( is_string($attributes)) - { - if(strpos('accept-charset=') === FALSE) - { - $attributes .= ' accept-charset="'.$charset.'"'; - } - } - else - { - $attributes = (array) $attributes; - - if ( ! in_array('accept-charset', $attributes)) - { - $attributes['accept-charset'] = $charset; - } - } + $attributes = 'method="post"'; } $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action; @@ -87,6 +66,7 @@ if ( ! function_exists('form_open')) } } + // ------------------------------------------------------------------------ /** @@ -978,6 +958,11 @@ if ( ! function_exists('_attributes_to_string')) $attributes .= ' method="post"'; } + if ($formtag == TRUE AND strpos($attributes, 'accept-charset=') === FALSE) + { + $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + return ' '.$attributes; } @@ -988,19 +973,24 @@ if ( ! function_exists('_attributes_to_string')) if (is_array($attributes) AND count($attributes) > 0) { - $atts = ''; + $atts = ''; - if ( ! isset($attributes['method']) AND $formtag === TRUE) - { - $atts .= ' method="post"'; - } + if ( ! isset($attributes['method']) AND $formtag === TRUE) + { + $atts .= ' method="post"'; + } - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } + if ( ! isset($attributes['accept-charset']) AND $formtag === TRUE) + { + $atts .= ' accept-charset="'.strtolower(config_item('charset')).'"'; + } + + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } - return $atts; + return $atts; } } } -- cgit v1.2.3-24-g4f1b From 7f3719faf120dc15f3d7b45e132ab3192f60ad62 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Tue, 5 Jan 2010 13:35:37 +0000 Subject: updated copyrights --- system/helpers/form_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 02e2edd3e..c78b805e5 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -6,7 +6,7 @@ * * @package CodeIgniter * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2009, EllisLab, Inc. + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com * @since Version 1.0 -- cgit v1.2.3-24-g4f1b From 33d4b6aac7f33d6cddfa5fb39c5701ecc9cfa80b Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Sun, 17 Jan 2010 07:23:00 +0000 Subject: adding the ability for form_open_multipart() to accept string attribute arguments --- system/helpers/form_helper.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index c78b805e5..60d2631e9 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -84,7 +84,15 @@ if ( ! function_exists('form_open_multipart')) { function form_open_multipart($action, $attributes = array(), $hidden = array()) { - $attributes['enctype'] = 'multipart/form-data'; + if (is_string($attributes)) + { + $attributes .= ' enctype="multipart/form-data"'; + } + else + { + $attributes['enctype'] = 'multipart/form-data'; + } + return form_open($action, $attributes, $hidden); } } -- cgit v1.2.3-24-g4f1b From 68788d5577d9f101220e3e6e8fba0829feb136de Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 5 Mar 2010 10:11:31 -0600 Subject: bringing form helper in sync --- system/helpers/form_helper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 60d2631e9..5feb3ce66 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -66,7 +66,6 @@ if ( ! function_exists('form_open')) } } - // ------------------------------------------------------------------------ /** @@ -266,7 +265,7 @@ if ( ! function_exists('form_textarea')) * @param string * @return type */ -if (! function_exists('form_multiselect')) +if ( ! function_exists('form_multiselect')) { function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') { @@ -320,7 +319,7 @@ if ( ! function_exists('form_dropdown')) { $key = (string) $key; - if (is_array($val)) + if (is_array($val) && ! empty($val)) { $form .= ''."\n"; @@ -638,7 +637,7 @@ if ( ! function_exists('form_prep')) if ($field_name != '') { - $prepped_fields[$field_name] = $str; + $prepped_fields[$field_name] = $field_name; } return $str; -- cgit v1.2.3-24-g4f1b From 958543a38c2c97b0ec4c10fc9faf4f0753143880 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Thu, 22 Jul 2010 14:10:26 -0400 Subject: Adding CSRF into config Adding CSRF token into form open() --- system/helpers/form_helper.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'system/helpers/form_helper.php') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 5feb3ce66..632f94505 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -62,6 +62,12 @@ if ( ! function_exists('form_open')) $form .= form_hidden($hidden); } + // CSRF + if ($CI->config->item('csrf_protection') === TRUE) + { + $form .= form_hidden($CI->security->csrf_token_name, $CI->security->csrf_hash); + } + return $form; } } -- cgit v1.2.3-24-g4f1b From fd2ba8836d74ded06cfe14f728387698c0532148 Mon Sep 17 00:00:00 2001 From: Greg Aker Date: Tue, 14 Sep 2010 18:45:42 -0500 Subject: Fix #96 html validation failure on csrf hidden input on form_open() in the form helper. Added