Welcome Guest, Not a member yet? Register   Sign In
Flashdata always seems one page behind
#1

[eluser]gabe[/eluser]
Hi there,

just started trying to use the flash. It seems that it is always 1 request behind. Consider the following code
Code:
$this->session->set_flashdata( 'flash', 'You have already provided us with your details' );
$this->load->view( 'competition_form' );

The flash message doesn't show the first time the view is loaded, only if refreshed. How can one get it to show in the view file?

I am actually trying to use it along with form validation and my full code looks like this:

Code:
if( $this->validation->run() == FALSE )
        {
            $this->session->set_flashdata( 'flash', 'Please fill in the form correctly…' );    
        }
        else
        {
            if( !$this->session->userdata( 'competition' ) )
            {
                $this->load->model( 'entry' );
                
                $this->entry->saveEntry();
                
                $this->session->set_userdata( 'competition', TRUE );
                
                $this->session->set_flashdata( 'flash', 'Thank you. Your details have been saved and a confirmation email sent.' );
            }    
            else
            {
                $this->session->set_flashdata( 'flash', 'You have already provided us with your details. Multiple submissions are not allowed.' );
            }
        }
        $this->load->view( 'competition_form' );
#2

[eluser]Pascal Kriete[/eluser]
The definition of flashdata is that it shows on the next page load. No the next view load. If you need text in a view just pass it as part of the data array.
#3

[eluser]gabe[/eluser]
thanks for the reply. So in what circumstance might you want to use flash data? Just so I can get some idea of when it might be useful for me. Thanks a lot.
#4

[eluser]Derek Allard[/eluser]
The manual gives a few examples of circumstances gabe, take a look. I also gave a few examples on my blog when I originally wrote these. http://www.derekallard.com/blog/post/enh...n-library/
#5

[eluser]gabe[/eluser]
Thanks, Derek

You have a well-nice blog!

Gabe
#6

[eluser]Chris.Campbell[/eluser]
I use flash say when an event happens, such as creating an account, logging in, posting..etc Smile Nice feedback for the user.
#7

[eluser]gabe[/eluser]
aha and then after setting the flash redirect to another page?




Theme © iAndrew 2016 - Forum software by © MyBB