From 39f6f5a7eafe05b6388833149c23cad809de53f6 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Mon, 22 Sep 2008 16:06:06 +0000 Subject: minor whitespace cleanup --- system/helpers/form_helper.php | 237 +++++++++++++++++++++-------------------- 1 file changed, 119 insertions(+), 118 deletions(-) diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 81331cda4..fc2592241 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -61,11 +61,11 @@ if ( ! function_exists('form_open')) { $form .= form_hidden($hidden); } - + return $form; } } - + // ------------------------------------------------------------------------ /** @@ -78,7 +78,7 @@ if ( ! function_exists('form_open')) * @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()) @@ -87,7 +87,7 @@ if ( ! function_exists('form_open_multipart')) return form_open($action, $attributes, $hidden); } } - + // ------------------------------------------------------------------------ /** @@ -100,7 +100,7 @@ if ( ! function_exists('form_open_multipart')) * @param mixed * @param string * @return string - */ + */ if ( ! function_exists('form_hidden')) { function form_hidden($name, $value = '') @@ -111,17 +111,17 @@ if ( ! function_exists('form_hidden')) } $form = ''; - + foreach ($name as $name => $value) { $form .= "\n"; $form .= ''; } - + 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