[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);
}