{"action":"created","issue":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/9187","labels_url":"https://api.github.com/repos/yiisoft/yii2/issues/9187/labels{/name}","comments_url":"https://api.github.com/repos/yiisoft/yii2/issues/9187/comments","events_url":"https://api.github.com/repos/yiisoft/yii2/issues/9187/events","html_url":"https://github.com/yiisoft/yii2/issues/9187","id":96587578,"number":9187,"title":"Flash message is not displayed when refresh/redirect","user":{"login":"houmamwazzeh","id":8778259,"avatar_url":"https://avatars.githubusercontent.com/u/8778259?v=3","gravatar_id":"","url":"https://api.github.com/users/houmamwazzeh","html_url":"https://github.com/houmamwazzeh","followers_url":"https://api.github.com/users/houmamwazzeh/followers","following_url":"https://api.github.com/users/houmamwazzeh/following{/other_user}","gists_url":"https://api.github.com/users/houmamwazzeh/gists{/gist_id}","starred_url":"https://api.github.com/users/houmamwazzeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houmamwazzeh/subscriptions","organizations_url":"https://api.github.com/users/houmamwazzeh/orgs","repos_url":"https://api.github.com/users/houmamwazzeh/repos","events_url":"https://api.github.com/users/houmamwazzeh/events{/privacy}","received_events_url":"https://api.github.com/users/houmamwazzeh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/yiisoft/yii2/labels/status:need%20more%20info","name":"status:need more info","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-07-22T14:55:06Z","updated_at":"2015-07-25T07:49:06Z","closed_at":"2015-07-23T07:04:23Z","body":"I reviewed the issues #2510 & #4415 but I still face the same problem. I display a contact form in the footer, so it is displayed in all pages, so I process the contact submition in beforeAction() method as follows:\r\n```php\r\nclass Controller extends \\yii\\web\\Controller {\r\n    public function beforeAction($event)\r\n    {\r\n        if ($this->footerContact->load(\\Yii::$app->request->post()) && $this->footerContact->contact(\\Yii::$app->params['infoEmail']))\r\n        {\r\n            $m = \\Yii::t('app', 'Thank you for contacting us. We will respond to you as soon as possible.');\r\n            \\app\\components\\Flash::success($m);\r\n            return $this->refresh();\r\n        }\r\n        return parent::beforeAction($event);\r\n    }\r\n}\r\n```\r\n\r\nAll my controllers are sub-classes from the above class and I use a special class to manage flash messages:\r\n\r\n```php\r\nclass Flash\r\n{\r\n    public static function add($type, $message)\r\n    {\r\n        \\Yii::$app->session->addFlash('app-flash-message',[\r\n            'type' => $type,\r\n            'message' => $message\r\n        ]);\r\n    }\r\n\r\n    public static function success($message)\r\n    {\r\n        self::add('success', $message);\r\n    }\r\n\r\n    public static function render()\r\n    {\r\n        $messages = \\Yii::$app->session->getFlash('app-flash-message');\r\n        if(! $messages )\r\n            return '';\r\n        // ELSE:\r\n        ob_start();\r\n        ob_implicit_flush(false);\r\n        echo Html::beginTag('div', ['class'=>'flash-overlay']);\r\n        echo Html::tag('div', '', ['class'=>'overlay']);\r\n        echo Html::beginTag('div', ['class'=>'inner']);\r\n        echo Html::tag('div', Html::a('&times;', '#'), ['class'=>'close-area']);\r\n\r\n        foreach ($messages as $flash)\r\n        {\r\n            echo Html::tag('div', $flash['message'], ['class'=>'alert alert-'.$flash['type']]);\r\n        }\r\n        echo Html::endTag('div');   // inner\r\n        echo Html::endTag('div');   // gr-msg-overlay\r\n\r\n        $view = \\Yii::$app->controller->getView();\r\n        $view->registerJs(\"\r\n            \\$('.flash-overlay .close-area a').click(function(){\r\n                \\$('.flash-overlay').remove();\r\n            })\r\n        \");\r\n\r\n        return ob_get_clean();\r\n    }\r\n}\r\n```\r\nFinally, I call Flash::render() in my layouts/main.php file to display the flash messages, but unfortunately, they are not displayed in this case. If I omit the line **return $this->refresh();** the message will be displayed, but in this case, the form will be re-submited when the user refresh (F5) the page.\r\n\r\nHere is a part of the composer.json file:\r\n```\r\n    \"minimum-stability\": \"stable\",\r\n    \"require\": {\r\n        \"php\": \">=5.4.0\",\r\n        \"yiisoft/yii2\": \">=2.0.4\",\r\n        \"yiisoft/yii2-jui\": \"~2.0.0\",\r\n        \"yiisoft/yii2-bootstrap\": \"*\",\r\n        \"yiisoft/yii2-swiftmailer\": \"*\",\r\n        \"bower-asset/slicknav\": \"*\"\r\n    },\r\n```"},"comment":{"url":"https://api.github.com/repos/yiisoft/yii2/issues/comments/124817729","html_url":"https://github.com/yiisoft/yii2/issues/9187#issuecomment-124817729","issue_url":"https://api.github.com/repos/yiisoft/yii2/issues/9187","id":124817729,"user":{"login":"houmamwazzeh","id":8778259,"avatar_url":"https://avatars.githubusercontent.com/u/8778259?v=3","gravatar_id":"","url":"https://api.github.com/users/houmamwazzeh","html_url":"https://github.com/houmamwazzeh","followers_url":"https://api.github.com/users/houmamwazzeh/followers","following_url":"https://api.github.com/users/houmamwazzeh/following{/other_user}","gists_url":"https://api.github.com/users/houmamwazzeh/gists{/gist_id}","starred_url":"https://api.github.com/users/houmamwazzeh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houmamwazzeh/subscriptions","organizations_url":"https://api.github.com/users/houmamwazzeh/orgs","repos_url":"https://api.github.com/users/houmamwazzeh/repos","events_url":"https://api.github.com/users/houmamwazzeh/events{/privacy}","received_events_url":"https://api.github.com/users/houmamwazzeh/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T07:49:06Z","updated_at":"2015-07-25T07:49:06Z","body":"After doing some DEBUG, I discovered that the problem comes from the client side where the form was submitted TWICE, because I use a JavaScript to process the form and submit it.\r\n\r\nThe both suggestions woks fine now:\r\n```php\r\npublic function beforeAction($event)\r\n{\r\n    if ($this->footerContact->load(\\Yii::$app->request->post()) && $this->footerContact->contact(\\Yii::$app->params['infoEmail']))\r\n    {\r\n        $m = \\Yii::t('app', 'Thank you for contacting us. We will respond to you as soon as possible.');\r\n        \\app\\components\\Flash::success($m);\r\n        $this->refresh();\r\n        return false;\r\n    }\r\n    return parent::beforeAction($event);\r\n}\r\n```\r\n```php\r\npublic function beforeAction($event)\r\n{\r\n    if(parent::beforeAction($event)) {\r\n        if ($this->footerContact->load(\\Yii::$app->request->post()) && $this->footerContact->contact(\\Yii::$app->params['infoEmail']))\r\n        {\r\n            $m = \\Yii::t('app', 'Thank you for contacting us. We will respond to you as soon as possible.');\r\n            \\app\\components\\Flash::success($m);\r\n            $this->refresh();\r\n            return false;\r\n        }\r\n        return true;\r\n    }\r\n    return false;\r\n}\r\n```\r\n\r\n\r\nSorry for bothering you for nothing worthy :disappointed:.\r\n\r\nThanks."}}