Vegas CMF Form Elements

Requirements

Before you use Upload Form Element make sure that you installed the "jquery-uploader" JS library. More information about the JS library you can find here: jquery-uploader. After implementation form element and embeding form inside the view, please make sure also if you set "uploadAction()" properly in controller file.

All required js and css files are included in vegas library. Check installation guide for more details.

Vegas\Forms\Element\Upload

Element to upload files.

Form

Minimal configuration:

namespace Category\Forms;

use Vegas\Forms\Element\Upload;
use Vegas\Forms\Form;

class Category extends Form
{
    public function initialize()
    {
        $upload = new Upload('files');
        $upload->setUploadUrl('/your/upload/url');
        $upload->getDecorator()->setTemplateName('jquery');
        $this->add($upload);
    }
}

Full configuration:

namespace Category\Forms;

use Vegas\Forms\Element\Upload;
use Vegas\Forms\Form;

class Category extends Form
{
    public function initialize()
    {
        $upload = new Upload('files');
        $upload->setUploadUrl('/your/upload}/url');
        $upload->getDecorator()->setTemplateName('jquery');
        $upload->setModel(new \File\Models\File()); //File model required by preview. It represents
        $upload->setPreviewSize(array('width' => 140, 'height' => 100)); //Size of preview images
        $upload->setMode(Upload::MODE_MULTI); //Upload multiple files. Constants MODE_MULTI, MODE_SINGLE
        $upload->addValidator(new SizeOf(array('min' => 1))); //SizeOf Validator
        $upload->setButtonLabels(array('add' => 'Add File')); //Sets label for add button
        $upload->setExtensions(array('jpg', 'png')); //Allowed extensions
        $upload->setMimeTypes(array('image/jpeg', 'image/png'));
        $upload->setTriggerType('button'); //Trigger for selecting files. Options: 'button', 'dropzone'
        $upload->setMaxFiles(4); //Sets max number of files
        $upload->setMaxFileSize(1024*1024); //Sets max size of upload file
        $upload->setBaseElements(array(
            new Text('title'),
            new Text('description'),
            ... //You can add whichever form element you want to single file
        ));
        $this->add($upload);
    }
}