We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22673
    • 72 Posts
    Yep noticed that. Have tried stripping back to only the required parameters, nothing is working!
      • 12028
      • 152 Posts
      @ paramaniac :

      I had just tried your form and have no problems with the attachment.

      The only thing I noticed are that the
      <p>[[+contactAttachment]]</p>
      placeholder are empty in the mail, but the file are attached correct.

      Just an idea: Could it be a problem with the tmp folder on the server? Missing, wrong path setup, or maybe write protected ?
        - A small step for mankind, so why not take two...

        Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!
        • 24287
        • 14 Posts
        Henrik, that’s interesting that the same code works for you. I haven’t heard of a tmp folder, where can I find and configure it?
          • 12028
          • 152 Posts
          Well - that depends on the platform, hosting provider etc. But if you have access to the php.ini you can find the folder name - but maybe it’s faster to contact the hosting provider, and ask them to check the settings ;-)
            - A small step for mankind, so why not take two...

            Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!
            • 24287
            • 14 Posts
            Thanks Henrik, phpinfo says that upload_tmp_dir has no value. This should be set to a folder with write permissions, right? I’ll ask the provider to change that, as I don’t have access to php.ini.
              • 22673
              • 72 Posts
              Hi Henrik,

              Thanks for the suggestion. I have just checked the system info and mine is saying the same as rabimoe, upload_tmp_dir: NO VALUE.

              I will try installing MODx on another server which may have different php.ini settings and see if that works...
                • 22673
                • 72 Posts
                I have tried a fresh install of MODx and Formit on a different server, the upload_tmp_dir setting is also NO VALUE.
                The file did not attach to the email.

                Interestingly, another website on the same server that I built a while ago using MODx 1.0.2 and eForm 1.4.4.6, has a file upload, and this works fine.
                  • 16868
                  • 24 Posts
                  Can someone update the instructions Wiki for formit to mention some of this stuff? Seems strictly going by what’s there won’t work for a lot of people... Many thanks!
                    • 22673
                    • 72 Posts
                    Tried stripping right back to this, with no luck:

                    Template
                    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
                    <html xmlns="http://www.w3.org/1999/xhtml">
                    <head>
                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                    <title>Formit Test</title>
                    </head>
                    <body>
                      
                        [[!FormIt?
                      	&submitVar=`submit`
                      	&hooks=`email`
                    	&emailTpl=`tplContactReport`
                    	&emailSubject=`Enquiry from the website`
                    	&emailTo=`XXXX`
                        ]]
                        
                        <form action="[[~[[*id]]]]" method="post" id="contactForm" enctype="multipart/form-data">
                          
                          <label for="contactName">Full Name</label><br />
                          <input type="text" name="contactName" id="contactName" />
                          <br /><br />
                    	      
                          <label for="contactEmail">Email</label><br />
                          <input type="text" name="contactEmail" id="contactEmail" />
                          <br /><br />
                          
                          <label for="contactPhone">Phone Number</label><br />
                          <input type="text" name="contactPhone" id="contactPhone" />
                          <br /><br />
                          
                          <label for="contactAttachment">CV Upload</label><br />
                          <input type="file" name="contactAttachment" id="contactAttachment" value="[[!+fi.contactAttachment]]" />
                          <br /><br />
                          
                          <label for="contactEnquiry">Enquiry</label><br />
                          <textarea name="contactEnquiry" id="contactEnquiry"></textarea>
                          <br /><br />
                          
                          <input type="submit" name="submit" id="submit" value="Submit" />
                    
                        </form>
                      
                    </body>
                    </html>


                    tplContactReport
                    <p><strong>Name:</strong> [[+contactName]]</p>
                    <p><strong>Email:</strong> [[+contactEmail]]</p>
                    <p><strong>Phone:</strong> [[+contactPhone]]</p>
                    <p><strong>Enquiry:</strong> [[+contactEnquiry]]</p>
                    <p>[[+contactAttachment]]</p>


                    The fact that the attachment filename is being pulled out successfully in tplContactReport makes me think that Formit is not treating the file as an attachment, merely a text string. As suggested, maybe this is because of a server setting? It is interesting that when Henrik Nielsen tried my code and it worked (attached the file to email), the <p>[[+contactAttachment]]</p> was left blank.

                    PS: created a bug report here: http://bugs.modx.com/issues/5132
                    Please add your experiences, suggestions.
                      • 22673
                      • 72 Posts
                      Found the part of Formit that processes file fields, see below.
                      Does the file field have to have a specific name=""? It would seem it has to be called name="attachment" or name="attachment0"

                        /* handle file fields */
                              foreach ($fields as $k => $v) {
                                  $attachmentIndex = 0;
                                  if (is_array($v) && !empty($v['tmp_name']) && isset($v['error']) && $v['error'] == UPLOAD_ERR_OK) {
                                      if (empty($v['name'])) {
                                          $v['name'] = 'attachment'.$attachmentIndex;
                                      }
                                      $this->modx->mail->mailer->AddAttachment($v['tmp_name'],$v['name'],'base64',!empty($v['type']) ? $v['type'] : 'application/octet-stream');
                                      $attachmentIndex++;
                                  }
                              }