Welcome Guest, Not a member yet? Register   Sign In
Unset post data.
#1

[eluser]JasonS[/eluser]
I need to unset post data to stop my form reloading it when I return a success message. I do not want to have to redirect a user back to the controller... or at least.. I shouldn't need to do this. How can I clear the post data?

Code:
public function Add()
{    
    // Set access level
    set_access('admin');
    
    $data = array();
    
    // Add a portfolio item
    // Fields : Title[r], Image, Content, URL, Client[r], Tags[r]
    $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
    
    if (isset($_POST))
    {
        // Run Form Validation
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('client', 'Client', 'required');
        $this->form_validation->set_rules('tags', 'Tags', 'required');
        
        if ($this->form_validation->run())
        {
            // Validate update and check file uploads
            $config['upload_path'] = './uploads/portfolio/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '100';
            $config['max_width']  = '1024';
            $config['max_height']  = '768';
            
            $this->load->library('upload', $config);
            
            // If upload fails
            if ( ! $this->upload->do_upload())
            {
                $data['error'] = $this->upload->display_errors('<p class="error">', '</p>');
            }    
            else // Add to database.
            {
                if ($this->port_model->save($this->upload->data()))
                {
                    $data['success'] = 'This item has been successfully added to the database.';
                    unset($_POST);
                }
                else
                {
                    $data['error'] = 'An error occurred when adding file to the database. Please try again.';
                }
            }
        }        
    }
        
    $this->load->view('portfolio/add_form', $data);
}


Messages In This Thread
Unset post data. - by El Forum - 02-10-2009, 07:09 AM
Unset post data. - by El Forum - 02-10-2009, 11:40 AM
Unset post data. - by El Forum - 11-08-2010, 05:02 AM
Unset post data. - by El Forum - 01-04-2011, 06:11 AM
Unset post data. - by El Forum - 01-04-2011, 11:56 AM
Unset post data. - by El Forum - 03-23-2011, 04:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB