1

I working for custom product form in backend on magento 2.1.1. Follow this tutorial: https://gielberkers.com/adding-custom-category-attributes-magento-2-1/.

But, have a problem, when I submit form, in controller, I can't get postValue for this field. Because attribute "name" of this input is blank. enter image description here

I want use this way to add an ui component file for this field to run some js code. This js code will run dependence for some other fields, and I can't fix this problem.

If you have solution please help me. Thank you so much.

  • Have you found a solution? I have the same issue. – WaPoNe Jan 29 '17 at 12:21
  • Sorry, no, I haven't solution to fix this issue. – Ronald Do Feb 15 '17 at 3:04
0

I hope you have added custom text filed (Custom Attribute) in your custom field set (Example) using the modifyData method, then you need to implement observer to get the post value.

First, declare it in the app/code/Namespace/Module/etc/adminhtml/events.xml file (we are using the adminhtml scope because the form doesn’t exist on the front-end):

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="catalog_product_save_after">
        <observer name="save_example_data" instance="Namespace\Module\Observer\ProductSaveAfter" />
    </event>
</config>

Then, create the observer’s class that we pointed in the instance attribute – app/code/Namespace/Module/Observer/ProductSaveAfter.php

<?php
namespace Namespace\Module\Observer;

use \Magento\Framework\Event\ObserverInterface;
use \Magento\Framework\Event\Observer as EventObserver;
use Namespace\Module\Ui\DataProvider\Product\Form\Modifier\CustomFieldset;

class ProductSaveAfter implements ObserverInterface
{

    /**
     * @param EventObserver $observer
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /** @var \Magento\Catalog\Model\Product $product */
        $product = $observer->getEvent()->getProduct();
        if (!$product) {
            return;
        }
        //change your field name as you have declare.
        $exampleTextField = $product->getData(CustomFieldset::FIELD_NAME_TEXT);

        // Manipulate data here
    }
}

Hope this will help you.

  • Thank you so much. I have added custom text field, but when submit form, this field not exist in $_POST data. So I can't use next step. – Ronald Do Sep 9 '16 at 1:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.