0

I am trying to retrive the upload file on form submit in admin grid.

In that I did not get the filepath because of the $model->getdata not able to find the path on line 123 in below code.

 <?php
        /**
        * Webkul_Grid Add New Row Form Admin Block.
        * @category    Webkul
        * @package     Webkul_Grid
        * @author      Webkul Software Private Limited
        *
        */
        namespace Webkul\Grid\Block\Adminhtml\Grid\Edit;
    /**
    * Adminhtml Add New Row Form.
    */
    class Form extends \Magento\Backend\Block\Widget\Form\Generic
    {
    /**
    * @var \Magento\Store\Model\System\Store
    */
    protected $_systemStore;

    /**
    * @param \Magento\Backend\Block\Template\Context $context,
    * @param \Magento\Framework\Registry $registry,
    * @param \Magento\Framework\Data\FormFactory $formFactory,
    * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
    * @param \Webkul\Grid\Model\Status $options,
    */
    public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Framework\Registry $registry,
    \Magento\Framework\Data\FormFactory $formFactory,
    \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig,
    \Webkul\Grid\Model\Status $options,
    array $data = []
    ) {
    $this-&gt;_options = $options;
    $this-&gt;_wysiwygConfig = $wysiwygConfig;
    parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
    * Prepare form.
    *
    * @return $this
    */
    protected function _prepareForm()
    {
    $dateFormat = $this-&gt;_localeDate-&gt;getDateFormat(\IntlDateFormatter::SHORT);
    $model = $this-&gt;_coreRegistry-&gt;registry('row_data');
    $form = $this-&gt;_formFactory-&gt;create(
    ['data' =&gt; [
    'id' =&gt; 'edit_form',
    'enctype' =&gt; 'multipart/form-data',
    'action' =&gt; $this-&gt;getData('action'),
    'method' =&gt; 'post'
    ]
    ]
    );

    $form-&gt;setHtmlIdPrefix('shipment_');

    $fieldset-&gt;addField(
    'content',
    'editor',
    [
    'name' =&gt; 'content',
    'label' =&gt; __('Content'),
    'style' =&gt; 'height:36em;',
    'required' =&gt; true,
    'config' =&gt; $wysiwygConfig
    ]
    );

    $fieldset-&gt;addField(
    'publish_date',
    'date',
    [
    'name' =&gt; 'publish_date',
    'label' =&gt; __('Publish Date'),
    'date_format' =&gt; $dateFormat,
    'time_format' =&gt; 'H:mm:ss',
    'class' =&gt; 'validate-date validate-date-range date-range-custom_theme-from',
    'class' =&gt; 'required-entry',
    'style' =&gt; 'width:200px',
    ]
    );
    $importdata_script =  $fieldset-&gt;addField(
    'importdata',
    'file',
    array(
    'label'     =&gt; 'Upload File',
    'required'  =&gt; true,
    'name'      =&gt; 'importdata',
    'note' =&gt; 'Allow File type: .csv and .xls',
    )
    );


    $importdata_script =  $fieldset-&gt;setAfterElementHtml(
    &quot;   


    &lt;script type=\&quot;text/javascript\&quot;&gt;

    document.getElementById('grid_importdata').onchange = function () { 

    var fileInput = document.getElementById('grid_importdata');

    var filePath = fileInput.value;

    var allowedExtensions = /(\.csv|\.xls)$/i; 

    if(!allowedExtensions.exec(filePath))
    {
    alert('Please upload file having extensions .csv or .xls only.');
    fileInput.value = '';
    }

    };

    &lt;/script&gt;&quot;
    );
    $form-&gt;setValues($model-&gt;getData());
    $form-&gt;setUseContainer(true);
    $this-&gt;setForm($form);

    return parent::_prepareForm();
    }
    }

Ankush Deora
  • 99
  • 10

0 Answers0