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

How to create multiple select field

Hello I create new item form using select element to make multiple select field like this

    $type = new Select('type[]', Types::find(), array(
        'using'     => array('id', 'name'),
        'useEmpty'  => true,
        'emptyText' => 'Select Type',
                'multiple' => 'multiple'
    ));

which is generate multiple select field in form and I can get post variable using

             $type = $this->request->getPost('type');
             if (is_array($this->request->getPost('type'))) {
                   $type = implode (", ", $this->request->getPost('type'));
             } else {
                   $type = $this->request->getPost('type');
             }

then keep text like 1,2 in database but I don't know how to make select field with selected value from database

        $item = Items::findFirstById($id);
        $this->view->form = new NewItemForm($item);

others field such as text and text area have value from database but select field not have any line selected

Is that possible? Thank you.



8.5k

Thank you Alex