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.

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

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.

  • @PatrickW Great!! you can upvoted this answer so other user can reach easily to there solution. – Rutvee Sojitra Aug 27 '18 at 12:10
  • I already tried that but due to having less point I can't do that. Will do. Thanks. – Patrick W Aug 27 '18 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, – Patrick W Sep 6 '18 at 11:11
  • @PatrickW Can you please ask this as different question so if not i may be other users can help you Thanks – Rutvee Sojitra Sep 6 '18 at 11:14

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.