1

hello everyone I want shows the uploaded image of the form in the mail to admin in mail image name is coming but I want to show the image

0

Image Form id field_name

Form.php

$fieldset->addType('productimage', '\Vendor\Module\Block\Adminhtml\Post\Renderer\Image');
$fieldset->addField('field_name', 'productimage', array(           
   'label'     => __('Image')));

Image.php

<?php
namespace Vendor\Module\Block\Adminhtml\Post\Renderer;

use Magento\Store\Model\StoreManagerInterface;

class Image extends \Magento\Framework\Data\Form\Element\AbstractElement
{                   
       private $_storeManager;
   /**
    * @param \Magento\Backend\Block\Context $context
    * @param array $data
    */
   public function __construct(\Magento\Backend\Block\Context $context, 
StoreManagerInterface $storemanager, array $data = [])
   {
       $this->_storeManager = $storemanager;
       parent::__construct($context, $data);
   }
    /**
     * get category name
     * @param  DataObject $row
     * @return string
     */
    public function getElementHtml()
    {
        // here you can write your code.
        $html = '';

        if ($this->getValue()) 
        {
            $html = $this->getMediaImageHtml($this->getValue());
        } 
        return $html;
    }
    public function getMediaImageHtml($imageName)
    {
        $mediaDirectory = $this->_storeManager->getStore()->getBaseUrl(
            \Magento\Framework\UrlInterface::URL_TYPE_MEDIA
    );
        $Image = $this->getValue(); 
        $html = "<img src='".$mediaDirectory.$Image."' height='250px' width='250px'>";        
        return $html;
    }
}
| improve this answer | |

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.