Welcome Guest, Not a member yet? Register   Sign In
Flashdata not clearing on refresh/redirect
#1

(This post was last modified: 02-12-2021, 07:54 AM by msheath.)

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.
Reply
#2

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

(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?
Reply
#4

(This post was last modified: 02-12-2021, 10:33 AM by demyr.)

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?
Reply
#5

(This post was last modified: 02-12-2021, 10:29 AM by msheath.)

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.
Reply
#6

(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.
Reply
#7

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

(This post was last modified: 03-18-2021, 04:13 AM by Muzikant.)

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

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

unset($_SESSION['some_name']);

after calling session data on view
[/quote]
Reply
#10

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB