XSS 过滤不会影响显示的输入字段值。
我看到两个选项:
1) 您可以手动创建 INPUT 元素:
<input type="text" name="title" value="<?php echo ($title) ? $title : $this->input->post('title'); ?>" />
2) 您可以修改 CodeIgniter 源代码(不推荐 - 以后可能会造成严重破坏)。
PS:这是 CodeIgniter 在显示 form_input 值时使用的函数(form_helper.php):
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;
}
如您所见,该函数正在使用 htmlspecialchars 和其他技巧。
更新 - CodeIgniter 示例:
// config.php: $config['global_xss_filtering'] = FALSE;
echo form_open("test");
echo form_input('title', ($this->input->post('title')) ? $this->input->post('title') : $title);
echo form_input('title', ($this->input->post('title')) ? $this->input->post('title') : $title, FALSE);
echo form_input('title', ($_POST['title']) ? $_POST['title'] : $title, FALSE);
echo "<input type=\"text\" name=\"title\" value=\"" . (($title) ? $title : $this->input->post('title')) . "\" />";
echo form_submit("btn", "Submit");
echo form_close();
// output:
<form action="/test/" method="post">
<input type="text" name="title" value="XYZ's survey report" />
<input type="text" name="title" value="XYZ's survey report" />
<input type="text" name="title" value="XYZ's survey report" />
<input type="text" name="title" value="XYZ's survey report" />
<input type="submit" name="btn" value="Submit" />
</form>