skip to Main Content

I’m trying to get data from a form to my controller. I’m using getRequest()->getParams() in my controller, but all I’m getting is the form key. What am I doing wrong?

The var_dump echoes out an array containing the key and form_key, and nothing else.

Controller:

    $data = $this->getRequest()->getParams();
    var_dump($data);

Block SaveButton:

public function getButtonData()
{
    return [
        'label' => __('Save'),
        'class' => 'save primary',
        'data_attribute' => [
            'mage-init' => ['button' => ['event' => 'save']],
            'form-role' => 'save',
        ],
        'sort_order' => 90
    ];

Form, from ui_component:

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">vendor_colorsort_add_new_mapping.vendor_colorsort_all_mappings_data_source</item>
            <item name="deps" xsi:type="string">vendor_colorsort_add_new_mapping.vendor_colorsort_all_mappings_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">Add New Mapping</item>
        <item name="template" xsi:type="string">templates/form/collapsible</item>
    </argument>
    <settings>
        <buttons>
            <button name="save" class="vendorColorSortBlockAdminhtmlFormEditSaveButton" />
        </buttons>
        <deps>
            <dep>vendor_colorsort_add_new_mapping.vendor_colorsort_all_mappings_data_source</dep>
        </deps>
    </settings>
    <dataSource name="vendor_colorsort_all_mappings_data_source">
        <argument name="dataProvider" xsi:type="configurableObject">
           <argument name="class" xsi:type="string">MagentoFrameworkViewElementUiComponentDataProviderDataProvider</argument>
           <argument name="name" xsi:type="string">vendor_colorsort_all_mappings_data_source</argument>
            <argument name="primaryFieldName" xsi:type="string">id</argument>
            <argument name="requestFieldName" xsi:type="string">mapping</argument>
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
                    <item name="submit_url" xsi:type="url" path="*/*/save" />
                    <item name="storageConfig" xsi:type="array">
                        <item name="indexField" xsi:type="string">id</item>
                    </item>
                </item>
            </argument>
        </argument>
    </dataSource>
    <fieldset name="mapping_form">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="collapsible" xsi:type="boolean">false</item>
                <item name="label" xsi:type="string" translate="true">Add New Mapping</item>
            </item>
        </argument>
        <field name="mapping">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="label" xsi:type="string">Mapping</item>
                    <item name="visible" xsi:type="boolean">true</item>
                    <item name="dataType" xsi:type="string">text</item>
                    <item name="formElement" xsi:type="string">input</item>
                    <item name="dataScope" xsi:type="string">mapping</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

2

Answers


  1. Please use:

       $data = $this->getRequest()->getPostValue();
    
    Login or Signup to reply.
  2. add datascope in setting

    <settings>
            <buttons>
                <button name="save" class="vendorColorSortBlockAdminhtmlFormEditSaveButton" />
            </buttons>
            <deps>
                <dep>vendor_colorsort_add_new_mapping.vendor_colorsort_all_mappings_data_source</dep>
            </deps>
            <dataScope>data</dataScope>
        </settings>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search