Magento 2: How to submit custom html content from ui_form to controller?
-
10-12-2020 - |
题
I am developing a module using ui_form. I have developed ui_form and on submit it post all fields except custom html fields.
For example:
<container name="pl_labelposition" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">30</item>
<item name="label" xsi:type="string" translate="true">Label Position</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">Company\Module\Block\Adminhtml\ProductLabel\Edit\LabelPosition</argument>
</htmlContent>
</container>
I also use conditions of sales rules:
<container name="conditions_apply_to" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Conditions</argument>
</htmlContent>
</container>
Could you help me to resolve this problem? I am not able to submit such fields to controller. How can i use in controller?
Help will be appreciated
Thank You in Advance
解决方案
In your block create
protected $_template = 'Company_Module::labelposition.phtml';
now, make labelposition.phtml
and add your html field with attribute data-form-part="formname"
.
Here the formname
must be name of your uiform like <uiComponent name="product_form"/>
.
e.g.
<input type="text" data-form-part="product_form" name="test" value="Hello World">
You will get the value of this field.