Skip to main content

Magento 2 uploaedupload image not showing in post form data

I have created a custom module and in the admin New/Edit form I added the image field but when I submit the form with uploading image, it won't show the image in save controller.

I used to add below code to add image field in admin from:

$fieldset->addField(
        'image',
        'image',
        array(
            'label' => __('Image'),
            'name'  => 'image',
            'class' =>'admin__control-image',
    )
    );

also in my form, I added the multipart form data as below:

protected function _prepareForm()
{
    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create(
        ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post' , 'enctype' => 'multipart/form-data']]
    );
    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

How to get rid of this issue?

Thanks in advance!

Magento 2 uploaed image not showing in post form data

I have created a custom module and in the admin New/Edit form I added the image field but when I submit the form with uploading image, it won't show the image in save controller.

I used to add below code to add image field in admin from:

$fieldset->addField(
        'image',
        'image',
        array(
            'label' => __('Image'),
            'name'  => 'image',
            'class' =>'admin__control-image',
    )
    );

also in my form, I added the multipart form data as below:

protected function _prepareForm()
{
    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create(
        ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post' , 'enctype' => 'multipart/form-data']]
    );
    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

How to get rid of this issue?

Thanks in advance!

Magento 2 upload image not showing in post form data

I have created a custom module and in the admin New/Edit form I added the image field but when I submit the form with uploading image, it won't show the image in save controller.

I used to add below code to add image field in admin from:

$fieldset->addField(
        'image',
        'image',
        array(
            'label' => __('Image'),
            'name'  => 'image',
            'class' =>'admin__control-image',
    )
 );

also in my form, I added the multipart form data as below:

protected function _prepareForm()
{
    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create(
        ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post' , 'enctype' => 'multipart/form-data']]
    );
    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

How to get rid of this issue?

Thanks in advance!

Source Link
Utsav Gupta
  • 1.2k
  • 1
  • 20
  • 52

Magento 2 uploaed image not showing in post form data

I have created a custom module and in the admin New/Edit form I added the image field but when I submit the form with uploading image, it won't show the image in save controller.

I used to add below code to add image field in admin from:

$fieldset->addField(
        'image',
        'image',
        array(
            'label' => __('Image'),
            'name'  => 'image',
            'class' =>'admin__control-image',
    )
    );

also in my form, I added the multipart form data as below:

protected function _prepareForm()
{
    /** @var \Magento\Framework\Data\Form $form */
    $form = $this->_formFactory->create(
        ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post' , 'enctype' => 'multipart/form-data']]
    );
    $form->setUseContainer(true);
    $this->setForm($form);
    return parent::_prepareForm();
}

How to get rid of this issue?

Thanks in advance!