Pregunta

Problem

I have a $fieldset. What arguments should I give to ->addField method to create an input field, that loads image to $_FILES?

What was done

For now I have an input field.

enter image description here

Created by

 $fieldset->addField('image',
            'image',
            [
                'title' => __('Image'),
                'label' => __('Image'),
                'name' => 'image',
                'note' => 'Allow image type: jpg, jpeg, gif, png',
            ]
        );

But the $_FILES is empty, when I checking it in controller execute() method.

Additional information

$fieldset arguments was taken from this example.

¿Fue útil?

Solución

Go to file app/code/Vendor/Modulename/Block/Adminhtml/Modulename/Edit/Form.php

there is 'enctype' => 'multipart/form-data'

 $form = $this->_formFactory->create(
            ['data' => ['id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post', 'enctype' => 'multipart/form-data']]
        );
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top