Home >php教程 >PHP源码 >CI表单数据回显函数set_value()改造

CI表单数据回显函数set_value()改造

PHP中文网
PHP中文网Original
2016-05-26 08:19:591157browse

将CI的set_value()函数进行改造,可以处理数组形式的字段。

if ( ! function_exists('set_value'))
{
    function set_value($field = '', $default = '')
    {
        $field_orgin=$field;
        if(strpos($field,'[')){
            list($field,$item)=explode('[',str_replace(']','',$field));
        }

        if(isset($_GET[$field]) && ! isset($_POST[$field])){
            if(isset($item) && !empty($item) && ($_GET[$field][$item])){
                return form_prep($_GET[$field][$item], $field_orgin);
            }
            return form_prep($_GET[$field], $field_orgin);
        }

        if (isset($_POST[$field])){
            if(isset($item) && !empty($item) && ($_POST[$field][$item])){
                return form_prep($_POST[$field][$item], $field_orgin);
            }
            return form_prep($_POST[$field], $field_orgin);
        }

        if (FALSE !== ($OBJ =& _get_validation_object())){
            return form_prep($OBJ->set_value($field_orgin, $default), $field_orgin);
        }
        return form_prep($default, $field_orgin);
    }
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn