config->site_url($action) : $action; $form = '
\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 */ if ( ! function_exists('form_prep')) { 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 */ if ( ! function_exists('parse_form_attributes')) { 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; } } // ------------------------------------------------------------------------ /** * 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 */