Drop Zone
The showDropZone
function is a versatile utility designed to simplify the integration of multiple Dropzones in your custom pages forms. With this function, you can dynamically create and configure Dropzones for various file upload fields, each with its own set of properties, such as accepted file types, maximum file size, and user-friendly messages.
Structure
Parameters
The function accepts a single parameter which is an array that contains your fields configurations for drop zone areas to be displayed
Call the showDropZone function inside a form in your custom page or dashboard files.
The parameter of the function will be an array of field configurations. Each configuration should specify the following properties:
label_name
: A label for the file upload field.
field_name
: A unique identifier for the field.
dictDefaultMessage
: The default message displayed in the Dropzone.
dictRemoveFile
: The text for the "Remove" link.
maxFiles
: The maximum number of files that can be uploaded.
maxFilesize
: The maximum file size in megabytes.
acceptedFiles
: The types of files that are accepted for upload (e.g., image/*, application/pdf).
sizeClass: The css size class of each field eg: col-md-12
The
showDropZone
function will generate the necessary HTML and JavaScript to create Dropzones based on the provided field configurations. Each Dropzone is uniquely identified by itsfield_name
.Users can drag and drop files into the Dropzones or click to upload files. The Dropzones provide visual feedback, and you can configure them to accept only specific file types and sizes.
As files are uploaded, the function handles the success event, allowing you to customize the behavior when a file is uploaded successfully. It also handles the removed file event, ensuring that files can be removed from the Dropzone.
Behind the scenes, the function uses AJAX requests to interact with the server, making it easy to upload and manage files. Files are associated with the respective input fields, and file links are stored for further use.
Uploaded files can easily be managed using the inbuilt file manager tool.
Example Usage
The above code is going to create 2 drop zones with fields named: profile_picture and id_front_pic
You can access the paths of the uploaded files via php . If multiple files are uploaded for each filed, the paths will be a comma separated string containing all the paths for the uploaded files.
Example To Access The Uploaded File Paths
The output of the above will be
I uploaded one file for each field and you can see the path of the files has been output as shown.
Drop Zone Output
Last updated