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

Why shows a flash messages without having pressed the submit button?

I want to know why a view show the flash message without having pressed the submit button

I have a menu layout for reuse

views/layouts/admin.volt

the menu is recursive

other views have forms (textbox, radio, select option ....)

views/users/create.volt
views/users/show.volt

the problem is that when you press a link redirects to a view showing the flash message of form

i am using inheritance of view and routing annottations

1-. Action -> views/users/create.volt
2-. Layout -> views/layouts/admin.volt
3-. Controller -> controllers/UserController
4-. Main -> views/index.volt

what is this problem?



5.7k

Can you provide the controller code where you set the form and the flash message?



17.7k
edited May '15
<?php

/**
 * @RoutePrefix("/users")
 */
class Users extends BaseController{

    /**
    * @Route("/register")
     */
    public function registerAction(){
         $UsersForm = new UsersForm;

        if (!$UsersForm->isValid($this->request->getPost())){
            foreach ($UsersForm->getMessages() as $message) {
                $this->flash->error($message);
                return $this->dispatcher->forward(array(
                    'controller' => 'users',
                    'action' => 'index'
                    ));
            }
        }
        .... 

    }

}