Welcome Guest, Not a member yet? Register   Sign In
Flashdata redirect
#1

[eluser]Kemik[/eluser]
Hi guys,

I'm trying to save a flashdata message once the user fills out a form to create a client and have it display when the user is redirected.

clients/create controller
Code:
function create()
    {
        /* Loaders */
        $this->load->helper('form');
        $this->load->library('form_validation');

        if ($this->form_validation->run() == FALSE)
        {
            /* Load views */
            $this->load->view('header');
            $this->load->view('clients_create');
            $this->load->view('footer');
            
        } else {
            
            $client = array(
                        'name' => $this->input->post('client_name'),
                        'telephone' => $this->input->post('client_telephone'),
                        'address' => $this->input->post('client_address')
                    );
            
            /* Post to model */
            $this->load->model('clients_model');
            $this->clients_model->insert_client($client);        
            
            /* Redirect */
            $this->session->set_flashdata('msg', 'Client created successfully.');
            redirect('clients');
            
        }

clients view
Code:
<h2>Clients</h2>
            <div class="inner-box clearfix">
            
            &lt;?php if($this->session->flashdata('msg')): ?&gt;
            <div class="success">
                &lt;?=$this->session->flashdata('msg')?&gt;
            </div>
            &lt;?php endif; ?&gt;

It seems like the flashdata isn't even created as no text box is displayed. Any suggestions? Session is set in the autoloader.
#2

[eluser]Tominator[/eluser]
Why are you using flashdata in this case?
#3

[eluser]Kemik[/eluser]
[quote author="Tominator" date="1269730082"]Why are you using flashdata in this case?[/quote]

Because the user gets redirected back to the clients controller from several others, including clients/delete, clients/edit and clients/create so they need different messages for each successful action.
#4

[eluser]Tominator[/eluser]
Oh, I am sorry ... stupid question Smile

But, I have next stupid question:
Do you have initialized session? ($this->load->library('session'); or auto-loaded)
#5

[eluser]Kemik[/eluser]
[quote author="Tominator" date="1269736098"]Oh, I am sorry ... stupid question Smile

But, I have next stupid question:
Do you have initialized session? ($this->load->library('session'); or auto-loaded)[/quote]

Yup. The session table shows "a:1:{s:13:"flash:new:msg";s:28:"Client updated suc..." in the database.




Theme © iAndrew 2016 - Forum software by © MyBB