1

Hi I need to get my custom module form data in getElementHtml(). Here is my form code:

$fieldset->addType(
        'mycustomfield',
        'MY\CustomModule\Block\Adminhtml\CustomModule\Renderer\Image'
    );  

    $fieldset->addField(
        'customdiv',
        'mycustomfield',
        [
            'name'  => 'customdiv',
            'label' => __('Custom Div'),
            'title' => __('Custom Div'),

        ]
    );

And below are my Image.php

<?php
namespace MY\CustomModule\Block\Adminhtml\CustomModule\Renderer;

use Magento\Backend\App\Action;

class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
{


public function getElementHtml()
{

    $id = $this->getRequest()->getParam('custommodule_id');
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();

    $model = $objectManager->create('MY\CustomModule\Model\CustomModule');
    $model->load($id);

    return $model;
}
}

Did not get ID here. Even not able to create Objectmanage. If I return just normal string it's only working like.

return 'Test';

It's working but not getting any data. Can anyone see to get custom_module ID.

If I return $id OR $model then I get below error:

Item Information Changes have been made to this section that have not been saved. This tab contains invalid data. Please resolve this before saving. 
1
  • Hi ravi, i have checked your requirement and you can try to get data from form registry. – shyam Aug 25 '17 at 12:12
1
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$custommodule = $objectManager->get('Magento\Framework\Registry')->registry('custommodule');
$custommodule->getId();
0

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $custommodule = $objectManager->get('Magento\Framework\Registry')->registry('custommodule'); $custommodule->getId();

1
  • The use of $objectManager directly is not recommended. – diazwatson Aug 25 '17 at 12:49

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.