Jump to:

23361 Posts in 18124 Topics by 2862 members

General Questions

SilverStripe Forums » General Questions » [SOLVED] Can't see uploaded files in form submit handler when using UploadField in front-end form, with no underlying model.

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 224 Views
  • vwd
    Avatar
    Community Member
    158 Posts

    [SOLVED] Can't see uploaded files in form submit handler when using UploadField in front-end form, with no underlying model. Link to this post

    I'm working on a front-end form which has an UploadField. There is no underlying model as the form data and the uploaded files are sent out as an email with attachments - no need to store anything in the database.

    What I'm finding though is that when the form is submitted, the files, although are uploaded to the specified upload folder, they are not listed in $data. Does anyone know if UploadField works without an underlying model?

    The UploadField is set up as follows:

    private function getUploadImagesFieldGroup() {
          $imageUploadField = new UploadField('UploadedImages', 'Upload Images');
          $imageUploadField->setCanAttachExisting(false);
          $imageUploadField->setCanPreviewFolder(false);
          $imageUploadField->relationAutoSetting = false;
          $imageUploadField->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif','tiff'));
          $imageUploadField->setFolderName('images/tmp-upload-images');
          $imageUploadField->setTemplateFileButtons('UploadField_FileButtons_ORS');
          
          $fg = new FieldGroup(            
             $imageUploadField
          );
          $fg->addExtraClass('upload ss-upload ss-uploadfield');    // had to add these classes because UploadField is added to FieldGroup
          $fg->setName('UploadImagesFieldGroup');
          
          return $fg;
       }

    In my form submission handler:

    public function formSubmissionHandler($data, $form) {
       // DEBUG
       var_dump($data['UploadedImages'];
       exit();
    }

    The output of the form submission:

    array (size=6)
       'Files' =>
          array (size=1)
             0 => string '49' (length=2)
       'name' =>
          array (size=1)
             'Uploads' =>
                array (size=1)
                   0 => string '' (length=0)
       'type' =>
          array (size=1)
             'Uploads' =>
                array (size=1)
                   0 => string '' (length=0)
       'tmp_name' =>
          array (size=1)
             'Uploads' =>
                array (size=1)
                   0 => string '' (length=0)
       'error' =>
          array (size=1)
             'Uploads' =>
                array (size=1)
                   0 => int 4
       'size' =>
          array (size=1)
             'Uploads' =>
                array (size=1)
                   0 => int 0

    Any idea why this could be happening? Any suggestions or workarounds?

    Thanks.
    VWD.

  • vwd
    Avatar
    Community Member
    158 Posts

    Re: [SOLVED] Can't see uploaded files in form submit handler when using UploadField in front-end form, with no underlying model. Link to this post

    Thanks to @simon_w who pointed out (on irc.silverstripe.com) that the '49' referred to the File ID of the already uploaded file.

    I noticed that $data['UploadedImages'] was appropriately filled when doing a non-AJAX upload. But when doing AJAX uploads, the File IDs of the uploaded files are present in array.

    224 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.