config->site_url($action);
}
elseif ( ! $action)
{
// If no action is provided then set to the current url
$action = $CI->config->site_url($CI->uri->uri_string());
}
$form = '
'.$extra;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('form_prep'))
{
/**
* Form Prep
*
* Formats text so that it can be safely placed in a form field in the event it has HTML tags.
*
* @param string|string[] $str Value to escape
* @param bool $is_textarea Whether we're escaping for a textarea element
* @return string|string[] Escaped values
*/
function form_prep($str = '', $is_textarea = FALSE)
{
if (is_array($str))
{
foreach (array_keys($str) as $key)
{
$str[$key] = form_prep($str[$key], $is_textarea);
}
return $str;
}
if ($is_textarea === TRUE)
{
return str_replace(array('<', '>'), array('<', '>'), stripslashes($str));
}
return str_replace(array("'", '"'), array(''', '"'), stripslashes($str));
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('set_value'))
{
/**
* 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
*
* @param string $field Field name
* @param string $default Default value
* @param bool $is_textarea Whether the field is a textarea element
* @return string
*/
function set_value($field = '', $default = '', $is_textarea = FALSE)
{
if (FALSE !== ($OBJ =& _get_validation_object()) && $OBJ->has_rule($field))
{
return form_prep($OBJ->set_value($field, $default), $is_textarea);
}
// We couldn't find the $field in validator, so try in $_POST array
$index = $field;
$container = $_POST;
// Test if the $field is an array name, and try to obtain the final index
if (preg_match_all('/\[(.*?)\]/', $field, $matches))
{
sscanf($field, '%[^[][', $index);
for ($i = 0, $c = count($matches[0]); $i < $c; $i++)
{
if (isset($container[$index]) && $matches[1][$i] !== '')
{
$container = $container[$index];
$index = $matches[1][$i];
}
else
{
$container = array();
break;
}
}
}
return isset($container[$index])
? form_prep($container[$index], $is_textarea)
: form_prep($default, $is_textarea);
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('set_select'))
{
/**
* Set Select
*
* Let's you set the selected value of a