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

Flash and dispatcher are not working after a jquery validation

I am using jquery.validate in order to validate my forms. The validation works, after the form is succesfuly validated it returns to my controller, I accepted the request, I have recorded the data in the table, but I can't get the flash message and I can't redirect to the page that originated the call. This is my jquery validation function

    $("#routenewForm").validate(
    {
    // Rules for form validation
    rules:
    {
    numeroId:
    {
    required: true
    },
    name:
    {
    required: true
    },
      email:
    {
    required: true,
      email: true
    },
      description:
    {
    required: true
    },
      phone:
    {
      required: true,
      minlength: 7,
      maxlength: 10
    },
      tipoId:
    {
      required: true,
    },
      address:
    {
      required: true,
    },
      customField1:
    {
      required: true,
    }
    },
      // Messages for form validation
      messages:
    {
    numeroId:
    {
    required: 'Ingrese su numero de identificacion'
    },
    address:
    {
    required: 'Ingrese una direccion de referencia'
    },
    customField1:
    {
    required: 'Ingrese una aclaracion del dato'
    },
    name:
    {
    required: 'Ingrese un nombre, descripcion, u observacion'
    },
      email:
    {
    required: 'Ingrese su direccion de correo electronico',
      email: 'Ingrese una direccion de correo electronico valida'
    },
      description:
    {
    required: 'Ingrese en forma mas completa nombre, descripcion, u observacion'
    },
      phone:
    {
    required: 'Ingrese un numero de telefono valido',
    minlength: 'Su numero de telefono debe ser de al menos 7 caracteres',
    maxlength: 'Su numero de telefono no puede tener mas de 10 caracteres'
    },
      tipoId:
    {
    required: 'Ingrese el tipo de identificacion'
    }
    },
      // Ajax form submition
      submitHandler: function(form)
      {
      $(form).ajaxSubmit(
      {
      beforeSend: function()
      {
      },
        uploadProgress: function(event, position, total, percentComplete)
        {
        $("#routenewForm .progress").text(percentComplete + '%');
        },
        success: function()
        {
        $("#routenewForm").addClass('submited');
          $('#routenewForm button[type="submit"]').removeClass('button-uploading').attr('disabled', false);
        }
      });
      },
      // Do not change code below
      errorPlacement: function(error, element)
      {
      error.insertAfter(element.parent());
      }
    });   

This is the action in my controller

    public function indexAction() {
        $form = new RouteNewForm();
        if ($this->request->isPost()) {
            $route = new Route();
            $id = $this->claves->guid();
            $route->setListid($id);
            $route->setEditsequence(rand(3000, 30000));
            $route->setName($this->request->getPost("name"));
            $route->setDescription($this->request->getPost("description"));
            $route->setAddress($this->request->getPost("address"));
            $route->setPhone($this->request->getPost("phone"));
            $route->setEmail($this->request->getPost("email", "email"));
            $route->setTipoid($this->request->getPost("tipoId"));
            $route->setNumeroid($this->request->getPost("numeroId"));
            $route->setCustomfield1($this->request->getPost("customField1"));

            if ($route->save() === false) {
                foreach ($route->getMessages() as $message) {
                    $this->flash->error($message);
                }
            } else {
                $this->flash->success('La ruta fue generada exitosamente');
                return $this->dispatcher->forward(
                      [
                         "controller" => "route",
                         "action" => "index",
                      ]
                );
                ;
            }
        }
        $this->view->form = $form;
    }

the portion of the code that is not working properly is

                $this->flash->success('La ruta fue generada exitosamente');
                return $this->dispatcher->forward(
                      [
                         "controller" => "route",
                         "action" => "index",
                      ]
                );

I added

$this->view->disable();

before

$this->flash->success("La ruta fue generada exitosamente");

And the flash message appears only if I refresh or push the 'atras' button.

Hi Carlos chequea por favor que estes utilizando el flash direct \Phalcon\Flash\Direct para los forwards y \Phalcon\Flash\Session para las redirecciones. docs

Good luck