Skip to main content
Magento

Return to Question

Notice removed Draw attention by Community Bot
Bounty Ended with no winning answer by Community Bot
added 1498 characters in body
Source Link

I am trying to get file upload working in a ui-component admin form. The file input field is coming from a htmlContent block. This is all sitting in a <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> element.

Now the issue is that the form element is not actually being rendered as html, as such I cannot add/apply enctype="multipart/form-data" to this form and $_FILES remains empty upon submitting.

Attempts to change the uiComponent to include form element and/or enctype definition failed as it doesn't allow usage of such elements/attributes in the ui-component file directly (collapsible.xhtml). How to move forward with this?

Code example:

Form definition

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <argument name="data" xsi:type="array">
 [...]
 <item name="template" xsi:type="string">templates/form/collapsible</item>
 <item name="enctype" xsi:type="string">multipart/form-data</item>
 </argument>
 <settings>
 [...]
 </settings>
 <dataSource name="XXX">
 [...]
 </dataSource>
 [...]
 <fieldset name="XXX" sortOrder="20">
 <settings>
 <collapsible>false</collapsible>
 <opened>true</opened>
 <label translate="true">Products</label>
 </settings>
 <htmlContent name="custom_field">
 <block name="html_content_input_field" class="XXXX">
 <arguments>
 <argument name="template" xsi:type="string">
 XXX.phtml
 </argument>
 </arguments>
 </block>
 </htmlContent>
 </fieldset>
</form>

XXX.phtml - Simplified as the file is nested in an array-like structure set up with Knockout

<div>
 <input type="file" name="nameforfile" data-form-part="the-correct-name"/>
</div>

All textual data is send - even the fake file name of the file but not the file itself. I don't need instant upload and/or visible files - Solely the data of the file actually being send to the server.

Raw POST data looks like:

------WebKitFormBoundaryvmSygS0ldVua30Aw
Content-Disposition: form-data; name="author_id"
1
[...] etc

I am trying to get file upload working in a ui-component admin form. The file input field is coming from a htmlContent block. This is all sitting in a <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> element.

Now the issue is that the form element is not actually being rendered as html, as such I cannot add/apply enctype="multipart/form-data" to this form and $_FILES remains empty upon submitting.

Attempts to change the uiComponent to include form element and/or enctype definition failed as it doesn't allow usage of such elements/attributes in the ui-component file directly (collapsible.xhtml). How to move forward with this?

I am trying to get file upload working in a ui-component admin form. The file input field is coming from a htmlContent block. This is all sitting in a <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> element.

Now the issue is that the form element is not actually being rendered as html, as such I cannot add/apply enctype="multipart/form-data" to this form and $_FILES remains empty upon submitting.

Attempts to change the uiComponent to include form element and/or enctype definition failed as it doesn't allow usage of such elements/attributes in the ui-component file directly (collapsible.xhtml). How to move forward with this?

Code example:

Form definition

<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
 <argument name="data" xsi:type="array">
 [...]
 <item name="template" xsi:type="string">templates/form/collapsible</item>
 <item name="enctype" xsi:type="string">multipart/form-data</item>
 </argument>
 <settings>
 [...]
 </settings>
 <dataSource name="XXX">
 [...]
 </dataSource>
 [...]
 <fieldset name="XXX" sortOrder="20">
 <settings>
 <collapsible>false</collapsible>
 <opened>true</opened>
 <label translate="true">Products</label>
 </settings>
 <htmlContent name="custom_field">
 <block name="html_content_input_field" class="XXXX">
 <arguments>
 <argument name="template" xsi:type="string">
 XXX.phtml
 </argument>
 </arguments>
 </block>
 </htmlContent>
 </fieldset>
</form>

XXX.phtml - Simplified as the file is nested in an array-like structure set up with Knockout

<div>
 <input type="file" name="nameforfile" data-form-part="the-correct-name"/>
</div>

All textual data is send - even the fake file name of the file but not the file itself. I don't need instant upload and/or visible files - Solely the data of the file actually being send to the server.

Raw POST data looks like:

------WebKitFormBoundaryvmSygS0ldVua30Aw
Content-Disposition: form-data; name="author_id"
1
[...] etc
Notice added Draw attention by vandijkstef
Bounty Started worth 50 reputation by vandijkstef
Source Link

Custom file upload in ui-component form

I am trying to get file upload working in a ui-component admin form. The file input field is coming from a htmlContent block. This is all sitting in a <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> element.

Now the issue is that the form element is not actually being rendered as html, as such I cannot add/apply enctype="multipart/form-data" to this form and $_FILES remains empty upon submitting.

Attempts to change the uiComponent to include form element and/or enctype definition failed as it doesn't allow usage of such elements/attributes in the ui-component file directly (collapsible.xhtml). How to move forward with this?

default

AltStyle によって変換されたページ (->オリジナル) /