I created a custom module with a multiselect type input.

My InstallSchema.php file contains this for this field.

    ['nullable => false'],

My Main.php file looks like

        'label' => __('Products'),
        'title' => __('Products'),
        'name' => 'elegible_products',
        'values' => \Ayakil\FreeGift\Block\Adminhtml\Freegifts\Grid::getValueArray4(),
        'disabled' => $isElementDisabled

This is my Grid.php file

static public function getOptionArray4()
    $data_array = array(); 
    $data_array[0] = 'a1';
    $data_array[1] = 'a2';


static public function getValueArray4()
    $data_array = array();
    foreach(\Ayakil\FreeGift\Block\Adminhtml\Freegifts\Grid::getOptionArray4() as $k => $v) {
        $data_array[] = array('value' => $k, 'label' => $v);


If i tried to save the form i am getting an error like below.

{"0":"Notice: Array to string conversion in /home/muja/www/ayakil-greens/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php on line 3105","1"

How can add Multiselect in custom admin form and save the data and retrieve the data here?


1 Answer 1


It seems like in your save controller, you need to set multiselect's value as a string. For eg :

$data['elegible_products'] = implode(',',$data['elegible_products']);

And then, you need to save records.

Hope, It will helpful for you.

  • 2
    thank you, This helped me.
    – Mujahidh
    Dec 31, 2019 at 5:41
  • welcome :) Happy coding !! Dec 31, 2019 at 5:42
  • After this, I am facing a new issue when I try to see the saved values for multi-select. When I see the form, the selected values are not visible. May 2, 2023 at 10:17

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .