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


            'name'  => 'customdiv',
            'label' => __('Custom Div'),
            'title' => __('Custom Div'),


And below are my Image.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');

    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. 
  • Hi ravi, i have checked your requirement and you can try to get data from form registry. – shyam Aug 25 '17 at 12:12
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$custommodule = $objectManager->get('Magento\Framework\Registry')->registry('custommodule');

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

  • 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.