0

当我收到验证错误时,设置值不会保持字段值。

*查看*:**

echo form_input('post_title', set_value('post_title')); 

控制器:

if ($this->form_validation->run('post_ad') == FALSE)
{
    set_temporary_msg(validation_errors('<div>', '</div>'));  
}

帮手:

function set_temporary_msg($msg, $target_location = '') 
{
    $CI =& get_instance();
    $CI->session->set_flashdata('temp_msg', $msg);
    redirect($target_location); 
}

function get_temporary_msg() {

    $CI =& get_instance();
    echo $CI->session->flashdata('temp_msg');

}

如果某些输入无效,则调用 set_temporary_msg()。在视图页面的顶部,我 echo get_temporary_msg();

错误消息和重定向工作正常,但我丢失了所有 set_value()。知道如何解决这个问题吗?

4

1 回答 1

0

这很正常,如果你在表单提交后进行重定向,set_value 找不到 post_title 的值,因为 $_POST 为空。如果你想保持提交的值,你必须在你的重定向 url 或会话中传递它。对不起我糟糕的英语..

于 2012-09-03T04:54:10.093 回答