We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Dynamic form content

I have a page which has an input parameter ie:

http://site.com/Page/index/1234

PageController creates a PageForm in indexAction($id):

Class PageController extends Phalcon\Mvc\Controller{
    public function indexAction($id){
        $form = new PageForm(null);
        $this->view->form = $form;
    }
}

In PageForm initialize() I want to pass $id to one of the form elements. So the values in this form element - which is a dropdown - should be dynamic based on the $id passed into PageController. I can't see any way to make PageForm "aware" of that $id that was passed in at runtime though. Is it in $option when I override initialize:

class PageForm extends Phalcon\Forms\Form{
    public function initialize ($entity = null, $option = null)
    ...
}

? If I do

Class PageController extends Phalcon\Mvc\Controller{
    public function indexAction($id){
        $form = new PageForm(null,array('id'=>$id);
        $this->view->form = $form;
    }
}

And then do print_r($option) inside PageForm's initialize() it is empty. Is this possible?