issue 472: Fixed a bug that radiobox's value is changed after displaying error messages

git-svn-id: http://xe-core.googlecode.com/svn/branches/1.5.0@9641 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
taggon 2011-10-13 09:19:48 +00:00
parent c1f1dae31c
commit 9f9c6dd9be

View file

@ -114,7 +114,7 @@ class HTMLDisplayHandler {
$keys = array_keys($INPUT_ERROR);
$keys = '('.implode('|', $keys).')';
$output = preg_replace('/(<input[^>]*?)(?:value="[^"]*"([^>]*?name="'.$keys.'"[^>])|(name="'.$keys.'"[^>]*?)(?:value="[^"]*")?)([^>]*?\/?>)/ise', '"\\1\\2\\4 value=\\"".@htmlspecialchars($INPUT_ERROR["\\3\\5"])."\\" \\6"', $output);
$output = preg_replace_callback('@(<input)([^>]*?)\sname="'.$keys.'"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $output);
}
if(__DEBUG__==3) $GLOBALS['__trans_content_elapsed__'] = getMicroTime()-$start;
@ -146,6 +146,33 @@ class HTMLDisplayHandler {
$oModuleController->replaceDefinedLangCode($output);
}
function _preserveValue($match)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
$str = $match[1].$match[2].' name="'.$match[3].'"'.$match[4];
// get type
$type = 'text';
if(preg_match('/\stype="([a-z]+)"/i', $str, $m)) $type = strtolower($m[1]);
switch($type){
case 'text':
case 'hidden':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.$INPUT_ERROR[$match[3]].'"';
break;
case 'radio':
case 'checkbox':
$str = preg_replace('@\schecked(="[^"]*?")?@', ' ', $str);
if(preg_match('@\s(?i:value)="'.$INPUT_ERROR[$match[3]].'"@', $str)) {
$str .= ' checked="checked"';
}
break;
}
return $str.' />';
}
/**
* @brief add html style code extracted from html body to Context, which will be
* printed inside <header></header> later.