magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.56k stars 9.32k forks source link

Unable to retrieve slected values in Multiselect form element #8981

Closed shifra123 closed 7 years ago

shifra123 commented 7 years ago

Preconditions

  1. Magento ver. 2.1.5
  2. PHP 7.0.16-3+deb.sury.org-trusty+1 (cli) (built: Feb 22 2017 10:27:05) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.16-3+deb.sury.org-trusty+1, Copyright (c) 1999-2017, by Zend Technologies with Xdebug v2.5.0, Copyright (c) 2002-2016, by Derick Rethans

Issue happens when adding a custom tab to customer_form.xml via block file

Steps to reproduce

  1. Add block to customer_index_edit.xml layout

  2. Block file extends \Magento\Backend\Block\Widget\Form\Generic implements TabInterface

  3. In function _prepareForm() adding a new filedset that will add a new form element

    
    $fieldset = $form->addFieldset('base_fieldset', ['legend' => __('Destinations')]);
    $fieldset->addField(
            'destination',
            'multiselect',
            [
                'name' => 'destination[]',
                'data-form-part' => $this->getData('target_form'),
                'label' => __('Destination'),
                'title' => __('Destination'),
                'values' => array( '1'=> array( 'label' => 'Customer', 'value' => 'customer'),
                    '2'=> array( 'label' => 'Shipping Agent', 'value' => 'shipping_agent'),
                    '3'=> array( 'label' => 'Customer Representative', 'value' => 'customer_representative'),
                ),
                'disabled' => false,
            ]
        );
  4. Run code

  5. Select more then one option in multiselect above

  6. Save form

  7. In save controller check the value of this $this->getRequest()->getPost('destination')

    Expected result

    It should return for the multiselect all options selected

Actual result

It always returns one option

TomashKhamlai commented 7 years ago

Hello! Thank you for reporting. Please provide the whole code of your controller.

When I tried to reproduce your issue I got this: i8981_1 i8981_2

Here is my code: Webkul.zip

Please check if the problem is actual for you.

shifra123 commented 7 years ago

@TomashKhamlai Thank for responding, Just added your code to my project and seems like the error still exist for me selection_030 selection_031

TomashKhamlai commented 7 years ago

Reproducible on 2.1.5, 2.1.6 and latest at this moment 2.1.7. Not reproducible on 2.2.0 (GitHub branch develop). Internal ticket MAGETWO-71177 was created to address this issue.

magento-engcom-team commented 7 years ago

@shifra123, thank you for your report. The issue is already fixed in 2.2.0