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

Select multiple default values from controller, how to?

I'm trying to set default values of a multiple select field from the controller but it's not working. I'm using "$this->tag->select" in the view with the name "select[]".

From the controller, I'm trying to use "$this->tag->setDefault('select', $default_values_array);" but it's not working because setDefault doesn't accept non scalar values.

How can I make it work?



33.8k

$defaultvaluesarray has to be an array with the values of the OPTIONs ([value1, value2, ...]).



12.2k

I know this is old, but for future reference (this is phalcon 2.0.9):


$form = new EntityForm($entity, ['edit' => true]);

$form->get('yourElementName[]')->setDefault($yourArrayOfValues);