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

[eluser]Kemik[/eluser]
Hello,

Current Setup

Here's a snippet current controller for my registration script

Code:
// Form submission        
        if ($this->validation->run() == TRUE) {
            
            // Load security helper and hash the password
            $this->load->helper('security');
            $password = dohash($this->input->post('pass'));
            
            // Insert user
            $this->user_model->create_user($this->input->post('username'), $password, $this->input->post('email'));
            $data['valid'] = TRUE;
            
        }
        
        $data['header'] = 'Sign Up';
        $data['page'] = 'user_create';
        $this->load->view('container', $data);

user_create_view

Code:
<p><b>Edit User</b></p>

&lt;?php if (isset($valid) && $valid == TRUE): ?&gt;
    
<p>You're account has been created.</p>  
    
&lt;?php else: ?&gt;

// form

&lt;?php endif; ?&gt;

To adjust this to use flashdata would the following be correct?

Code:
// Form submission        
        if ($this->validation->run() == TRUE) {
            
            // Load security helper and hash the password
            $this->load->helper('security');
            $password = dohash($this->input->post('pass'));
            
            // Insert user
            $this->user_model->create_user($this->input->post('username'), $password, $this->input->post('email'));
            $this->session->set_flashdata('msg', "You're account has been created.");
            
        }
        
        $data['header'] = 'Sign Up';
        $data['page'] = 'user_create';
        $this->load->view('container', $data);

And the view

Code:
<p><b>Edit User</b></p>

&lt;?php if (isset($this->session->flashdata('msg'))): ?&gt;
    
<p>&lt;?php echo $this->session->flashdata('msg'); ?&gt;</p>  
    
&lt;?php else: ?&gt;

// form

&lt;?php endif; ?&gt;

If so, what's the difference flashdata provides?
#2

[eluser]David Rothera[/eluser]
With your first example you have to set valid to be true or false, meaning only two possible messages.

However if you use flashdata then you could have the script come back with a multitude of error/success messages such as that the email address that was entered is already active in the system.
#3

[eluser]Kemik[/eluser]
Yeah but I already do those checks with error feedback using the validation class and callbacks.
#4

[eluser]Craig A Rodway[/eluser]
Flashdata will be available on the next page request (eg. if you were to use the redirect() function). You are only loading a view file, so it has no access to the flashdata at the time of loading.




Theme © iAndrew 2016 - Forum software by © MyBB