duanbo2048 2014-01-27 09:00
浏览 59
已采纳

如何在提交后清除表单数据?

I have form with a file input in my CodeIgniter website. When I fill in the form and click the submit button it's working fine. However, when I refresh the browser the same form data is uploaded again. How can I prevent this ?

input form

<form name="image_upload" action="<?= base_url() ?>admin/image_move_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">  
    <ul>  
        <li class="ui-field"><label for="filename">File Name :</label></li>
        <li class="ui-input"><input type="text"  name="filename" placeholder=""></li>  
        <li class="ui-field"><label for="file">Image( *only .jpg) :</label></li> 
        <li class="ui-input"><input type="file" name="imagefile" value="" placeholder="" required=""></li>  
        <li><input type="submit"  name="Upload" class="ui-submit"></li>  
    </ul>  
</form>

controller section

function image_move_upload() {
    $data['errors'] = NULL;
    $data['success'] = NULL;

    if (isset( $_POST['Upload'] )) {
      $config_arr = array(
            'upload_path' => './uploads/slider/',
            'allowed_types' => 'jpg',
            'max_size' => '2048',
            'max_width' => '1024',
            'max_height' => '768',
            'encrypt_name' => true,
            'file_name'  => 'sanji.jpg',
        );
        $this->load->library('upload', $config_arr);
        if (!$this->upload->do_upload('imagefile')) {
            $data['errors'] = $this->upload->display_errors(); // this isn't working                
        } else {
            $data['qs'] = $this->upload->data();
            $data['success'] = "File Uploaded Successfully";
        }         
    }

    $data['main_content'] = 'admin/upload';
    $this->load->view('admin_layout', $data);
}
  • 写回答

3条回答 默认 最新

  • douwen5546 2014-01-27 09:37
    关注

    redirect to same controller with refresh. Use following code.

    redirect('admin/image_move_upload', 'refresh');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?