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
    Quote from: sapphire at Jul 16, 2015, 12:10 PM
    update
    The problem #2 (queue not getting filled from prehook) is solved by the same ugly hack in Formit2AjaxUpload.

    Try it with the latest version. There was an issue in the PreHook that could have stopped the execution.
      • 42415
      • 115 Posts
      Quote from: Jako at Aug 03, 2015, 04:55 AM
      Quote from: sapphire at Jul 16, 2015, 12:10 PM
      update
      The problem #2 (queue not getting filled from prehook) is solved by the same ugly hack in Formit2AjaxUpload.

      Try it with the latest version. There was an issue in the PreHook that could have stopped the execution.

      Hi Jako,

      I just upgrade to latest version & I deleted the Formit2AjaxUpload Pre-Hook.

      Now I no longer have any errors in Modx manager, I also do not have any javascript errors in console.

      However, the upload files are failing, I'm getting this message after click upload:

      File_name.pdf0.1MBFailed

      I have created a folder called tentrucks here; assets/upload/tentrucks directory.

      This is the code now:

      [[!FormIt?
         &preHooks=`[[!profile]]`
         &hooks=`AjaxUpload2Formit,email`
         &ajaxuploadFieldname=`filer`
         &ajaxuploadTarget=`assets/uploads/tentrucks/`
         &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`]]


      And the ajaxupload in formit:

      [[!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`
      ]]


      When get this upload fail what is the usual or most likely cause for this?
        • 13428 ☆ A M B ☆
        • 1,031 Posts
        Could you please update to 1.2.0-pl2. There was an issue in the connector introduced in 1.2.0.
          • 36448
          • 58 Posts
          However, the upload files are failing, I'm getting this message after click upload:

          File_name.pdf0.1MBFailed

          Yes, I get the same message. My error log:
          (ERROR @ .../core/components/ajaxupload/model/ajaxupload/ajaxupload.class.php : 67) Recoverable error: Object of class modDocument_mysql could not be converted to string.

          I use the AjaxUpload 1.2.0-pl2 with MODX REVO 2.3.5-pl (php 5.6.10 | mysql 5.6.24)

          Thank you for your advice
            • 13428 ☆ A M B ☆
            • 1,031 Posts
            Should be fixed with 1.2.0-pl3.
              • 36448
              • 58 Posts
              Quote from: Jako at Aug 08, 2015, 08:11 AM
              Should be fixed with 1.2.0-pl3.
              Great! The error is gone.

              Unfortunately no attachments are sent. The files are in the folder assets/files but not in the mail. Did I forgot something? Here my small FormIt test chunk:

              [[!FormIt?
              &preHooks=`Formit2AjaxUpload`
              &hooks=`AjaxUpload2Formit,email`
              &ajaxuploadFieldname=`attach`
              &ajaxuploadTarget=`files/`
              &ajaxuploadUid=`attach`
              &emailTpl=`emailChunk`
              &emailTo=`[email protected]`
              &emailSubject=`TEST`
              &validate=`name:required
              ]]
              
              <form action="[[~[[*id]]]]" method="post" class="form-inline" role="form" enctype="multipart/form-data">
              
              <div class="input-group">
                <span class="input-group-addon">Name:</span>
                <input required type="text" class="form-control" name="name" id="name" value="[[!+fi.name:htmlent]]">
                <span>[[+fi.error.name]]</span>
              </div>
              
              [[!AjaxUpload?
              &uid=`attach`
              &allowedExtensions=`jpg,jpeg,png,gif`
              &thumbX=`75`
              &thumbY=`75`
              ]]
              
              <button type="submit" class="btn btn-large btn-success">SEND</button>
              </form>
              
                • 13428 ☆ A M B ☆
                • 1,031 Posts
                AjaxUpload is not built for handling attachments. But since you know the filename and the place where the file is saved you could easily build a hook for this on the base of https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-275342 better this: https://forums.modx.com/thread/47642/solved-attach-local-file-not-from-form#dis-post-496618
                  • 36448
                  • 58 Posts
                  Quote from: Jako at Aug 08, 2015, 01:14 PM
                  AjaxUpload is not built for handling attachments.
                  Thanks Jako, now I understand: yet another hook ;-)
                    • 36448
                    • 58 Posts
                    Hi, here is my "Attachment" hook and that works with one file:
                    <?php
                    $attach = $hook->getValue('attach');
                    //$modx->log(modX::LOG_LEVEL_ERROR,'Placeholder attachWeb: '.$attach);
                    
                    if(!empty($attach)){
                      $attach = substr($attach, 1); //remove the first slash
                      $hook->modx->getService('mail', 'mail.modPHPMailer');
                      $hook->modx->mail->mailer->AddAttachment($attach);
                    }
                    return true;


                    For multiple attachment files I had tried to set the AjaxUpload uid as array, like this:

                    [[!AjaxUpload?
                    &uid=`attach[]`
                    &allowedExtensions=`jpg,jpeg,png,gif`
                    &thumbX=`75`
                    &thumbY=`75`
                    ]]


                    However this doesn't work. Any Idea?

                    PS: I believe FormIt need this parser code
                    <input type="file" name="attach[]" multiple="multiple">
                    ?
                      • 13428 ☆ A M B ☆
                      • 1,031 Posts
                      The filenames are saved in ajaxuploadFieldname:
                      $ajaxuploadFieldname = $modx->getOption('ajaxuploadFieldname', $scriptProperties, '');
                      $ajaxuploadFieldformat = $modx->getOption('ajaxuploadFieldformat', $scriptProperties, 'csv');
                      if ($ajaxuploadFieldname) {
                        $attach = $hook->getValue($ajaxuploadFieldname);
                        if ($ajaxuploadFieldformat == 'json') {
                          $attach = json_decode($attach);
                        } else {
                          $attach = explode(',', $attach);
                        }
                        …
                        You have use ajaxuploadTarget parameter in this hook too to get the full path for the files.
                        …
                        $hook->modx->getService('mail', 'mail.modPHPMailer');
                        $hook->modx->mail->mailer->AddAttachment($attach);
                      }
                      

                      The AjaxUpload code is available https://github.com/Jako/AjaxUpload/ (i.e. for a PR of an additional AjaxUploadAttachment snippet) [ed. note: Jako last edited this post 11 years, 2 months ago.]