Skip to content

[BUG]: Multiselect does not work. #16946

@dev-fan

Description

@dev-fan

Multiselect does not work.

Steps to reproduce the behavior:
Open the page, select something in the multiselect field, and submit.

<?php

declare(strict_types=1);

require_once '../init.php';

use Phalcon\Filter\Filter;
use Phalcon\Forms\Element\Submit;
use Phalcon\Forms\Element\Select;
use Phalcon\Forms\Form;

class ExampleForm extends Form
{
    public function initialize(?object $entity = null, array $options = [])
    {
        ////////////////////////////////////////////////////////////////////////////// Multi select
        $list = [
            1 => 'Home',
            2 => 'Work',
            3 => 'Mobile',
        ];
        $multiselect = new Select('multiselect', $list, [
            'name'     => 'multiselect[]',
            'multiple' => true,
            'size'     => 3,
        ]);
        $multiselect->setLabel('Multiselect');
        $multiselect->setFilters([Filter::FILTER_TRIM, Filter::FILTER_ABSINT]);
        $this->add($multiselect);
        $submit = new Submit('submit', ['id' => 'register', 'value' => 'Send']);
        $this->add($submit);
    }
}

$dto = new \stdClass();
$dto->multiselect = null;
$form = new ExampleForm($dto);
if ($di['request']->isPost()) {
    echo '<div style="border: 2px solid blue;">$_POST: ';var_dump($di['request']->getPost());echo '</div>';;
    if ($form->isValid($di['request']->getPost(), $dto)) {
        echo '<div style="border: 2px solid blue;">DTO after isValid: ';var_dump($dto);echo '</div>';;
    }
}
echo (new Phalcon\Support\Version())->get() . '<br/>';
?><form method="POST" ><?php
foreach ($form as $element) {
    echo $element->render(); // line 47
}
?></form>

There shouldn't be a warning; the specified elements should be selected after submitting.

Screenshots
Image

Details

  • Phalcon version: (5.12.0)
  • PHP Version: (PHP 8.4.20 (cli) (built: Apr 11 2026 07:43:26) (NTS))
  • Operating System: Ubuntu Server 24.04
  • Zephir version (if any):
  • Server: Nginx

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

No fields configured for Bug.

Projects

Status
Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions