CodeIgniter Forums
How To Clear Data in Form_validation? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How To Clear Data in Form_validation? (/showthread.php?tid=43777)



How To Clear Data in Form_validation? - El Forum - 07-22-2011

[eluser]NotoriousWebmaster[/eluser]
Instead of going to a separate page on successfully writing the form's data to the DB, I'd like to return to the same page, so the user can add another record; but I want the data fields to be empty. I'm using the value="<?= set_value('field_01') ?>". So how do I clear that data out?

Thanks for your help,
- AAA


How To Clear Data in Form_validation? - El Forum - 07-22-2011

[eluser]cideveloper[/eluser]
just redirect back to the "controller/function" that displays the form.

Code:
function function1() {
    if ($this->form_validation->run() == FALSE)
    {
        $data = array (
            '' => ''
        );
        $this->load->vars($data);
        $this->load->view('form');
    }
    else
    {
        $result = $this->model->add2db($this->input->post('field_01', TRUE));
        redirect('/controller/function1');
    }        
}