We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13428 ☆ A M B ☆
    • 1,031 Posts
    The queue is filled with the value of the field during editing. The original uploaded images are copied to the upload cache then. That way the uploaded images could be changed.

    If I remember right, the deleted images in the queue are not deleted in the target automatic.
      • 50764
      • 5 Posts
      Jako,

      I'm not intending to delete images in the target, I just wanted the stale queue to flush. In my case, the queue doesn't get filled from FormIt field for some reason (though I do call the Formit2AjaxUpload prehook), but instead I see stale session-dependent queue values, exactly the ones that got uploaded last time. Like, if I load the same resource editing in a new browser session, I see an empty queue. But in the first window I see the queue with those old files uploaded.

      To be clear, I'm now facing three problems at once.

      1. The queue doesn't flush (SOLVED it with $ajaxUpload->clearValue()).
      2. The queue doesn't get prefilled from FormIt values (the FormIt value is set right, but no images are displayed in ajaxUpload).
      3. For some reason placeholders don't get processed and are passed into the ajaxUpload, so ajaxUpload maked a UID like this: "property-photos-[[+form_uid]]". Using uncached form [[!+form_uid]] doesn't help. I've made a couple of ugly hacks in AjaxUpload2Formit to solve it (manual str_replace, though I hate ugly hacks really), but it's still present in other parts of ajaxUpload. I suspect that this might be related to the above problems as well. Any ideas?
        • 50764
        • 5 Posts
        update
        The problem #2 (queue not getting filled from prehook) is solved by the same ugly hack in Formit2AjaxUpload. It looks like this:
        $scriptProperties['uid'] = str_replace("[[+form_uid]]", $modx->getPlaceholder("form_uid"), $scriptProperties['uid']);

        I hate it but it works. Hope to hear ideas of how to solve this in a proper way. ModX pisses me off with its "sometimes I just won't process your placeholders and you'll never know why!" behaviour.
          • 50764
          • 5 Posts
          False alarm guys. Looks like I was on mushrooms or something. The placeholders that I tried to use were set in the preHook. Surely they weren't processed when I expected. Moved those placeholders setting in a separate snippet that's run before FormIt. Now everything works fine, all issues solved.

          PS: but the issue with the queue not flushing was real, yes. And $ajaxUpload->clearValue() solved it, yes.

          Jako, thanks again for your great work!
            • 38323
            • 26 Posts
            Hi I have a problem setting a dynamic &ajaxuploadTarget.

            I wish to use a value set from another hook 'FormIt2db_Custom'. This hook saves data to a database table and returns the id of the new created database element:
            $resourceid = $dataobject->get('id');
            $hook->setValue('resourceid',$resourceid);


            I need this $resourceid in my ajaxuploadTarget, like:

            [[FormIt?
            &hooks=`FormIt2db_Custom,createuploadfolders_formit_hook,AjaxUpload2Formit,redirect`
            &preHooks=`db2FormIt,Formit2AjaxUpload`
            &ajaxuploadFieldname=`attachments`
            &ajaxuploadTarget=`uploads/offers/[[!+modx.user.id]]/[[!+fi.resourceid]]`


            Somehow I can't seem this to get it right. When i debug, the value of ajaxuploadTarget = assets/uploads/offers/3/[[!+fi.resourceid]]

            Anybody got some advice?

            Thanks!
            Michiel
              • 50764
              • 5 Posts
              vlijmscherp, from what I understood, [[+fi....]] placeholders are unset before the [[FormIt]] call. So your [[+fi.resourceid]] is passed in the ajaxuploadTarget parameter unresolved. You need to get that resourceid before this snippet call, maybe use an extra snippet for that.
                • 13428 ☆ A M B ☆
                • 1,031 Posts
                You could try to change the scriptProperties array in the custom formit2db hook.

                $scriptProperties['ajaxuploadTarget'] = 'xxx';
                  • 42415
                  • 115 Posts
                  Just installed this but I am getting errors:

                  /home/shipsave/public_html/core/components/ajaxupload/model/ajaxupload/ajaxupload.class.php : 305) PHP warning: Invalid argument supplied for foreach()
                  [2015-08-01 19:25:09] (ERROR @ /home/shipsave/public_html/core/components/ajaxupload/model/ajaxupload/ajaxupload.class.php : 305) PHP warning: Invalid argument supplied for foreach()


                  The pre hook and hooks code:

                  [[!FormIt?
                     &preHooks=`Formit2AjaxUpload`
                     &hooks=`AjaxUpload2Formit, email`
                     &ajaxuploadFieldname=`filer`
                     &ajaxuploadTarget=`assets/uploads/user/`
                     &ajaxuploadUid=`filer`
                     &emailFrom=`[email protected]`
                     &emailTpl=`myEmailChunk`
                     &emailTo=`[[+demail]]`
                     &emailCC=`[email protected]`
                     &emailSubject=`Your Delivery Request Quote`
                     &validate=`dname:required,
                        demail:required,
                        workmail:blank,
                        province:required,
                        datepicker:required,
                        country:required,
                        package:required,
                        method:required,
                        name4:required,
                        name2:required,
                        name1:required,
                        name3:required,
                        comment:required:stripTags`
                  ]]	 


                  The AjaxUpload:

                  [[!AjaxUpload?
                  &uid=`filer`
                  &allowedExtensions=`jpg,jpeg,png,pdf,PDF,DOC,DOCX,XLX,XLSX,doc,docx,xls,xlsx`
                  &maxFiles=`5` 
                  &maxFilesizeMb=`12` 
                  &thumbX=`75`
                  &thumbY=`75`
                  ]]


                  The errors are timed when I click submit.
                  I receive the email, but, there is no folder created in the user name at `assets/uploads/user/`

                  I'm kind of hoping someone can understand the error I'm receiving because I'm unsure what I have done wrong.
                    • 42415
                    • 115 Posts
                    From the above, I just changed this line:

                    &ajaxuploadTarget=`assets/uploads/user/`


                    Changed it to this line:

                    &ajaxuploadTarget=`assets/uploads/[[!+modx.user.username]]/`


                    But I am still getting errors:

                    [2015-08-01 20:49:51] (ERROR @ /home/shipsave/public_html/core/components/ajaxupload/model/ajaxupload/ajaxupload.class.php : 305) PHP warning: Invalid argument supplied for foreach()

                    The folder is not created and no files have been uploaded, however the email is sent.

                    What I am trying to do is upload pdf files to a folder that is the same name as the registered User name, the largest pdf is only 320kb so size is not an issue.

                    Am I correct in thinking that if the folder does not exist then it will be created?
                    Also once created then the registered user can continue every day uploading different files to his folder?

                    Each registered user must be able to upload up to 6 pdf files during each submission and have permission for an unlimited amount of submissions every day.

                    If I can get past this error can this AjaxUpload extra achieve what I want it to do?
                      • 13428 ☆ A M B ☆
                      • 1,031 Posts
                      Your error settings are a bit strong. The Formit2AjaxUpload hook breaks during deleteExisting method because of the warning that $_SESSION['ajaxupload'][$this->config['uid'] . 'delete'] is not an array. This is fixed fixed in AjaxUpload 1.2.0.

                      You could do your task with AjaxUpload and some extra hooks:

                      The target path has to exist. You could create it with another hook before calling the AjaxUpload2Formit hook.

                      If you only want to upload new files with each submit, you don't need the preHook. That hook is used to fill the queue with existing data. You should create another hook after the AjaxUpload2Formit hook that uniques the uploaded filenames and renames the files. Otherwise files could be overwritten.