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条)

报告相同问题?

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码