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

Form Select Option

How can i select an default option in the form generator ? value wont do anything .

$form->add(new Select("department", Departments::find(),[
            'using' => ['_','department'],
            'class' => "form-control",
            'data-validate' => true,
            'data-empty'    => "* Campo Obrigatório",
            'value'         => $member->department_id
        ]));

Hello, just tested and its working as intended. Make sure to dump $member and see if it holds correct value.



85.5k
edited Apr '16

the way I do it :

$form->get('selectName')->setDefault(MyValue)->render('selectName');

I am not 100% sure, but while i was digging into the sources, i think default value comes only from post ( not get ) or something like that, there was something fishy in there but i am not 100% what it was and why I went for my workaround