0

How can I add the attribute enctype="multipart/form-data" to the <form> tag in the configuration page for a module? That attribute is needed to upload a file to the server.

I am trying to upload a spreadsheet to the server so it can be parsed and have the records inserted into the database. This must be done from the admin section of the module.

I think adding that attribute would be the easiest way to send a chosen file to the server for processing. If there is a better suggestion, please let me know.

Here is the <config> section of my mod_<x>.xml file:

<config>
    <fields name="params">
        <fieldset name="basic">
            <field name="fileUpload" type="file" default="" label="Data File" accept=".csv"
                   description="File containing records to upload to database."/>
        </fieldset>
    </fields>
</config>

1 Answer 1

2

The short answer is there's an "easier" way. The assumption being you need to provide a means for a user to upload a file as part of the core configuration of the module. Since there isn't a mechanism to override extension configuration layouts in back-end views, the best solution IMO is to use the media field instead for file uploads.

This will open a modal to the media folder view, and more importantly, provide the proper UI for uploading files. In addition, it provides the added benefit of allowing admins to use existing files already uploaded and not requiring you to write the server side code which handles the saving of the file to the file system.

You might need to edit the allowed MIME types depending on what kind of file is being uploaded.

Joomla Media Field Type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.