Can't share form object within a whole application using Phalcon Forms Manager

Hello everyone. Could somebody please tell me if I am doing something wrong with my code. I am trying to use a Forms Manager object to share a form within an applicaiton. Here is my code: Set up:

$di->set('forms', function (){
    return new Phalcon\Forms\Manager();
});

In my index controller:

$this->forms->set('register', new RegistrationForm());
//used $this->forms->create() method as well, but it also didn't work.

The form is visible in my index controller, but the form is being posted to a Signin controller and I want to get the form there in order to validate the fields, but I get a message that form with a name 'register' doesn't exist. Signin Controller code :

$form = $this->forms->get('register');

What am I doing wrong? Would be grateful for any help



84.5k

You have to register the forms globally so it can be available everywhere:

$di->set('forms', function () {
    $form = new Phalcon\Forms\Manager();
    $form->set('register', new RegistrationForm());
    return $form;
});