Welcome Guest, Not a member yet? Register   Sign In
Dynamic Form with saving post data
#1

[eluser]carlhussey[/eluser]
I am pretty new to codeigniter / OOP but I am giving it a shot and a little stumped at this point.

I have 2 functions. One is the search which loads data from a model. The other is the save function.

My issue is, when running save() I am getting errors because its trying ti display the validation errors but we no longer have the data from the database that we got from the search() function.

I feel that it would be redundant to include all the details form the search back into this save function which is why I think I am doing something wrong.

Code:
public function search()
    {

        // Define some vars
        $data['title'] = 'Submit Attrition';
        $data['js_file'] = 'submit.js';

        // Load our helper
        $this->load->helper('form');

        // Get the user and pass it to the model
        $empQID = $this->input->post('empQID');  
        $data['userDetails'] = $this->submit_model->get_details($empQID);
        $data['languages'] = $this->submit_model->get_languages();
        $data['types'] = $this->submit_model->get_types();
        $data['ratings'] = $this->submit_model->get_ratings();
        $data['processes'] = $this->submit_model->get_processes();

        // Send the data to the views      
        $this->load->view('templates/header', $data);
        $this->load->view('submit/search', $data);
        $this->load->view('templates/footer', $data);
    }

    /**
    * Validate & save attrition submission
    *
    * @author   Carl
    * @return   void
    */
    public function save()
    {
        $data['title'] = 'Submit Attrition';
        $this->load->library('form_validation');
        $this->form_validation->set_rules('language', 'Supporting Language', 'required');

        // Validation failed, show form w/ validation errors
        if ($this->form_validation->run() === FALSE)
        {
            $this->load->view('templates/header', $data);
            $this->load->view('submit/search', $data);
            $this->load->view('templates/footer', $data);
        }
        else
        {
            // Success : Send data to model
            $this->submit_model->save_attrition();
            $this->load->view('templates/header', $data);
            $this->load->view('submit/success', $data);
            $this->load->view('templates/footer', $data);
        }  
    }


Messages In This Thread
Dynamic Form with saving post data - by El Forum - 10-03-2014, 10:37 AM
Dynamic Form with saving post data - by El Forum - 10-03-2014, 04:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB