We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12151
    • 115 Posts
    hi there,
    this is a fabulous script!
    may i suggest that a powerful addition would be to enable saving of uploaded files to the file system?
    thanks smiley
      • 12151
      • 115 Posts
      Quote from: highlander at Oct 23, 2007, 05:19 AM

      may i suggest that a powerful addition would be to enable saving of uploaded files to the file system?

      if anyone’s interested i solved my own query as follows

      while setting the field and values array for the insert statement i added this code:
      if($fields[fileAttachment]!=''){
        $strFilename = basename($_FILES['fileAttachment']['tmp_name'].'_'.$_FILES['fileAttachment']['name']);
        $dbTable[attachment] = $strFilename; 
        $target_path = 'assets/uploads/'.$strFilename;
        move_uploaded_file($_FILES['fileAttachment']['tmp_name'], $target_path);
      }

      however i discovered that this would save the file to the server but the file stopped being attached to my eForm report email. so i changed the &eFormOnBeforeMailSent param to &eFormOnMailSent and it now attaches the file to the email and also saves it to the server.

      if any of you cleverer types can think of a better way to do this please let me know! smiley

        • 29774
        • 386 Posts
        @highlander

        How about storing the file in the database rather than the filesystem? I find this useful for preventing files from being downloaded by unauthorised users. You need two tables, one for file metadata and one for the file data itself which broken into chunks and stored in incremental rows. See my post here for an idea of how to do it:
        http://uk.php.net/features.file-upload

          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
          • 6726
          • 7,075 Posts
          Quote from: pixelchutes at Sep 18, 2007, 11:13 PM
          Actually, yes, you can use the DBAPI for alternate DB access.
          Check the wiki here: http://wiki.modxcms.com/index.php/Access_another_database_from_MODx


          Sorry to dig an old post here, but I am currently looking into using eForm2db with an alternate DB.

          I have read the wiki’s article, and my take on it was that the snippet would have to cover 3 cases :
          1) use the MODx DB : the current snippet code covers that
          2) use an alternate DB on the same server
          3) use an alternate DB on a different server.

          As you might know, my php skills are very beginner-ish so to speak... how would you go about this : my thought was, create a parameter to set this directly in the snippet call (e.g [!eForm2db? &db=`same` ..... !]).

          Quote from: pixelchutes
          Essentially, database_2.table_name does the trick!

          Does this mean that I just need to add those at the beginning of the snippet ?

          * Different Database, Same Server :

          [tt]$ds = $modx->db->select(’*’,’database_name.table_name’);[/tt]

          * Different Database, Different Server :

          [tt]$db = new DBAPI($host,$database, $uid,$pwd);
          $ds = $db->select(’*’,’table_name’);[/tt]

          Thanks for any pointer, which could help me get started smiley




            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 33372
            • 1,611 Posts
            Basically, yes that’s all you need to do. You’re just declaring a new database object in order to access the one that’s on a different server, and by doing so you can use the same classes and methods as you would for the database that contains your MODx content. The second line in your "Different Database, Different Server" code is just an example of how you’d access that object using the DBAPI, since the syntax is slightly different from when you’re using the usual database (not much though).
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 6726
              • 7,075 Posts
              Ok thank you I’ll get down to trying that out smiley !
                .: COO - Commerce Guys - Community Driven Innovation :.


                MODx est l'outil id
                • 23491 ☆ A M B ☆
                • 1,056 Posts
                Quote from: pixelchutes
                Essentially, database_2.table_name does the trick!

                Please keep in mind MySQL user permissions when accessing separate databases on the same server. Your MySQL user will need to have access to the database/tables in question in order for this method to work smiley
                  Mike Reid - www.pixelchutes.com
                  MODx Ambassador / Contributor
                  [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                  ________________________________
                  Where every pixel matters.
                  • 6726
                  • 7,075 Posts
                  Thanks for the tip, I’ll definitely make sure permission are set correctly smiley
                    .: COO - Commerce Guys - Community Driven Innovation :.


                    MODx est l'outil id
                    • 22897 ☆ A M B ☆
                    • 209 Posts
                    This approach is great and I am using it to save form submissions to a database table.

                    However, is there any way to get data from the [tt]eFormOnBeforeMailSent[/tt] callback snippet back into eForm so it can be used in the email? For example, I’d like to include the row ID of the new database record in the email - and somehow need to communicate this from the DBSnippet to eForm!
                      MAPLEDESIGN MODX development and MODX web design and custom development. Proud to serve UK and International clients!
                      • 30223
                      • 1,010 Posts
                      Quote from: pbowyer at Nov 20, 2007, 10:32 AM

                      This approach is great and I am using it to save form submissions to a database table.

                      However, is there any way to get data from the [tt]eFormOnBeforeMailSent[/tt] callback snippet back into eForm so it can be used in the email? For example, I’d like to include the row ID of the new database record in the email - and somehow need to communicate this from the DBSnippet to eForm!

                      Yes there is. Add the value to the $fields array in your eFormOnBeforeMailSent function and make sure you have a placeholder for it in the report template.

                      $fields['record_id'] = $newRedordId; 

                      Report:
                      blah blah blah:....
                      The record number is: [+record_id+]
                      blah blah..