We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

What is the right way to clear Flash Session?

I'm outputing flashSession in my View using this method - flashSession.output(). When i reload the page the flash messages are still there. How can i remove them in a right way? Sequence like this does not work: flashSession.output(). flashSession.clear().



9.3k
Accepted
answer

This should work automatically flashSession.output(), output has one parameter $remove and its default value is true. Looks like you are populating flash messages on reload again.



14.8k

yes you are right, when reload the page, i re-submit my form again and get the messages again. Thnx



118

@Paul, so, what did you do to solve this problem?



14.8k
edited Apr '18

@biyro02, Hey, it was long ago, but I've just looked into it for you :)

I moved flashout elsewhere and no longer used it to display entered values in my form. Instead I used session post vars in the value attribute as you can see below:

Look at this line <input type='text' name="month" class="form-control" *value="{% if postVars['month'] is defined %}{{ postVars['month']}}{% endif%}" />

<div class="col-md-3 columns">
                    <div class="form-group">
                        <label for="name">Select Month:</label>
                        <div class='input-group date' id='datetimepicker1'>
                            <input type='text' name="month" class="form-control" *value="{% if postVars['month'] is defined %}{{ postVars['month']}}{% endif%}" />
                            <span class="input-group-addon">
                                <span class="glyphicon glyphicon-calendar">
                                </span>
                            </span>
                        </div>
                    </div>
                </div>

The whole page code you can find on my Github page



118

@paul, thank you for your answer. I have the same error but I didn't see any solution. My project is huge. This is not coded by mine. So, there are many flash.output using. I can not try this way. Now, I used flashSession->clear, flashSession->getMessages(false) and flashSession->setAutoScape(false) methods. Now I have a very interesting and difficult the explain error. I hope I will solve. Thanks again!