3

I have implemented admin form using UI component. In that, I have 3 separate tabs. Among 3, I have displayed one tab using custom phtml file by using following code in ui component form xml file

<fieldset name="custom_fieldset" sortOrder="30">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="label" xsi:type="string" translate="true">Manage Titles</item>
            <item name="collapsible" xsi:type="boolean">true</item>
        </item>
    </argument>
    <container name="custom_container">
        <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">Namespace\Module\Block\Adminhtml\Module\Labels</argument>
        </htmlContent>
    </container>
</fieldset>

But when I click on save button I am not getting any data in save controller post variable from this particular phtml file. I am getting data of other 2 tabs which implemented using field tag as we do normally with ui component.

This is my phtml file code :

<div class="fieldset-wrapper" id="manage-titles-wrapper">    
<div class="fieldset-wrapper-content in collapse" id="manage-titles-content">
    <fieldset class="admin__fieldset fieldset">
        <div class="admin__control-table-wrapper">
            <table class="admin__control-table" id="attribute-labels-table">
                <thead>
                <tr>
                    <?php foreach ($block->getStores() as $_store): ?>
                        <th class="col-store-view"><?= /* @escapeNotVerified */ $_store->getName() ?></th>
                    <?php endforeach; ?>
                </tr>
                </thead>
                <tbody>
                <tr>
                    <?php foreach ($block->getStores() as $_store): ?>
                        <td class="col-store-view">
                            <input class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>" type="text" name="frontend_label[<?= /* @escapeNotVerified */ $_store->getId() ?>]" value="" <?php if ($block->getReadOnly()):?> disabled="disabled"<?php endif;?>/>
                        </td>
                    <?php endforeach; ?>
                </tr>
                </tbody>                    
            </table>
        </div>
    </fieldset>
</div>

This is my block code

    <?php

namespace Namespace\Module\Block\Adminhtml\Module;

class Labels extends \Magento\Backend\Block\Template
{
    /**
     * Block template
     *
     * @var string
     */
    protected $_template = 'labels.phtml';

    /**
     * AssignProducts constructor.
     *
     * @param \Magento\Backend\Block\Template\Context  $context
     * @param array                                    $data
     */
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        array $data = []
    ) {
        parent::__construct($context, $data);
    }

    /**
     * Retrieve stores collection with default store
     */
    public function getStores()
    {
        return $this->_storeManager->getStores();
    }
}

Any help into this will be highly appreciable.

Thanks.

4
  • Can you please add your phtml code in question? Aug 27, 2018 at 11:48
  • @RutveeSojitra I have added the code you mentioned. Please check. Aug 27, 2018 at 11:50
  • Can Please also provide Namespace\Module\Block\Adminhtml\Module\Labels code in question Aug 27, 2018 at 11:56
  • @RutveeSojitra Kindly check now. Aug 27, 2018 at 12:00

2 Answers 2

7

You have to just add

data-form-part="forrname_form" in your input filed forrname_form it's must be similar with your ui form name

your code shold be like now:

    <tr>
                <?php foreach ($block->getStores() as $_store): ?>
                    <td class="col-store-view">
                        <input data-form-part="forrname_form" class="input-text<?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>" type="text" name="frontend_label[<?= /* @escapeNotVerified */ $_store->getId() ?>]" value="" <?php if ($block->getReadOnly()):?> disabled="disabled"<?php endif;?>/>
                    </td>
                <?php endforeach; ?>
            </tr>

The data-form-part HTML element’s attribute allows you to include the element’s value to the data submitted to the server.

6
  • @PatrickW Great!! you can upvoted this answer so other user can reach easily to there solution. Aug 27, 2018 at 12:10
  • I already tried that but due to having less point I can't do that. Will do. Thanks. Aug 27, 2018 at 12:12
  • Hello @Rutvee. This works fine with textbox. But If I use upload image button then I am getting this type of image path "C:\fakepath\apple.png" in postdata. Do you have any idea about this? Thanks, Sep 6, 2018 at 11:11
  • @PatrickW Can you please ask this as different question so if not i may be other users can help you Thanks Sep 6, 2018 at 11:14
  • @RutveeSojitra can you please check this magento.stackexchange.com/questions/328812/…
    – amith lal
    Jan 4, 2021 at 12:45
0

Adding to Rutvee's answer, it is also possible to set the data-form-part in code like so:

$fieldset->addField('example_field', 'text', [
    'label' => __('Example Field'),
    'name' => 'example_field',
    'data-form-part' => 'sales_rule_form'
]);
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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