CodeIgniter Forums
Flashdata not clearing on refresh/redirect - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Flashdata not clearing on refresh/redirect (/showthread.php?tid=78596)



Flashdata not clearing on refresh/redirect - msheath - 02-12-2021

Using CI 3.1.11:
I am sending a flashdata error message when a form is filled incorrectly. The message is appearing correctly but does not clear on refresh/redirect.

Controller method includes:

Code:
$this->session->set_flashdata('message', '<div class="alert alert-danger">The fields Model, Actual, Photo, Drawing and Painting can only be either blank or contain X</div>');

The session array looks like this:

Code:
array (size=5)
  'logged_in' => boolean true
  'firstname' => string 'Mike' (length=4)
  'lastname' => string 'Heath' (length=5)
  'message' => string '<div class="alert alert-danger">The fields Model, Actual, Photo, Drawing and Painting can only be either blank or contain X</div>' (length=129)
  '__ci_vars' =>
    array (size=1)
      'message' => string 'new' (length=3)
and I think the '__ci_vars' array element is what marks out 'message' as flashdata. Is that how it should appear? If correct, why does the session array stay the same when I refresh the browser tab?

I have researched this extensively via Google but have seen nothing helpful. As a further note, I have changed flashdata to tempdata with an expiry time of 10sec and the same behaviour persists. I can read the error message but it does not expire and refreshing the screen does not get rid of the message. I have to log out and log in again to do that.


RE: Flashdata not clearing on refresh/redirect - demyr - 02-12-2021

May I ask why you are keeping it within your array?


RE: Flashdata not clearing on refresh/redirect - msheath - 02-12-2021

(02-12-2021, 07:50 AM)demyr Wrote: May I ask why you are keeping it within your array?
I'm not doing that consciously - it just appears like that. How would I do it differently?


RE: Flashdata not clearing on refresh/redirect - demyr - 02-12-2021

Well,
in your controller:

1- get the data from your view (You can check the link I am leaving for step 2)
2 check if they pass your rules or not (Follow this link)
3- if yes, pass them to model.
4- if not, turn back an error (no need for flashdata).

- - - -

3- If you pass your data to model and to database successfully then you can call your flashdata, like:

PHP Code:
$data = [
  'name' => $name,
  'surname' => $surname,

etc..

];

$result $this->MyModel->lets_do_sth($data);
if(
$result){
$this->session->set_flashdata('success_message''You did it.');

        redirect('lets_go_to_login');



By the way, why don't you go with CI 4?


RE: Flashdata not clearing on refresh/redirect - msheath - 02-12-2021

Well my existing controller method follows the same pattern:

Code:
    public function log_illustration_update($id)
    {
        $data = $this->input->post();

        (($data['painting'] != 'X') && ($data['painting'] != null)) ? $entry = false : $entry = true;

        if ($entry == false) {
            $this->session->set_tempdata('message', '<div class="alert alert-danger">The fields Model, Actual, Photo, Drawing and Painting can only be either blank or contain X</div>',10);
            redirect('dashboard/log_illustration_detail/'.$id);
        } else {
            $log_illustration = $this->log_illustrations_model->_update($id, $data);
            if ($log_illustration) {
                $this->session->set_flashdata('message', '<div class="alert alert-success">The log_illustration details were successfully updated!!</div>');
            } else {
                $this->session->set_flashdata('message', '<div class="alert alert-danger">There was an error and the log_illustration details were not updated</div>');
            }
            redirect('dashboard/log_illustration_detail/'.$id);
        }
    }
so I'm still baffled. And by the way I'm not new, I've been using CI for years - never had this issue before.


RE: Flashdata not clearing on refresh/redirect - mskarn - 03-04-2021

(02-12-2021, 02:58 AM)msheath Wrote: Using CI 3.1.11:
I am sending a flashdata error message when a form is filled incorrectly. The message is appearing correctly but does not clear on refresh/redirect.

I have the same issue after upgrading from PHP 7.4 to PHP 8.0.2.


RE: Flashdata not clearing on refresh/redirect - mskarn - 03-04-2021

Looks like this will be fixed in 3.1.12: https://github.com/bcit-ci/CodeIgniter/pull/6013


RE: Flashdata not clearing on refresh/redirect - Muzikant - 03-18-2021

I can confirm this bug in CodeIgniter 3.1.11. The flashdata are not cleared on PHP 8 and acts like normal session data.


RE: Flashdata not clearing on refresh/redirect - Garnet - 09-30-2021

[quote pid="384357" dateline="1613123894"]
You can use 

unset($_SESSION['some_name']);

after calling session data on view
[/quote]


RE: Flashdata not clearing on refresh/redirect - InsiteFX - 10-03-2021

If your writing an application it is best to leave caching turned off while testing yurn it on when you need to
test the caching. You can also use the new opcache in php which will speed up your app 10 fold.