We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54641
    • 10 Posts
    Hello, I wan't to ask if is possible to use the FileUpload Snippet to upload multiples archives to multiples Paths.

    Example:

    <div>
    <form>
    
    [[!FileUpload ?
    <!--
    Image 1 -> Path A
    Image 2 -> Path B
    Image 2 -> Path C
    -->
    ]]
    
    <input>
    
    </form>
    </div>
    


    I'm trying to make a Upload Page with Multiple Fields and Only one button,

    I hope you can help me! smiley
      MODx Version: 2.6.5-pl
      Developing in Local Page with:
      > MAMP 5.0
      > PHP 7.2.7
      • 3749
      • 24,544 Posts
      There's no way to do that directly without multiple FileUpload tags on the page (which you might be able to style to look like a single form -- be sure to call them uncached).

      As a (very hacky) alternative: FileUpload fires the OnFileManagerUpload System Event so you could possibly use a plugin attached to that event that moves the files to the desired location, assuming that you could identify the location from the file name, type, extension, or size.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 54641
        • 10 Posts
        Quote from: BobRay at Oct 15, 2018, 10:52 PM
        There's no way to do that directly without multiple FileUpload tags on the page (which you might be able to style to look like a single form -- be sure to call them uncached).

        As a (very hacky) alternative: FileUpload fires the OnFileManagerUpload System Event so you could possibly use a plugin attached to that event that moves the files to the desired location, assuming that you could identify the location from the file name, type, extension, or size.

        How I can made the snippet work with multiple tag calls? I tried but I didn't get a useful result, here is my code:
        <div class="fu-outer">
            [[+fu-message]]
            <form enctype="multipart/form-data" action="[[~[[*id]]]]" method="post">
        
        <h2> upload Profile Pic</h2><br><br>
        
        [[!FileUpload?
                        &allowoverwrite=`1`
                        &filefields=`1`
                        &createpath=`assets/media/images/[[+modx.user.id]]` 
                        &path=`assets/media/images/[[+modx.user.id]]/` 
                        &extensions=`jpg,jpeg,png,gif` 
                        &messagetpl=`fuMessageTpl` 
                        &innertpl=`fuInnerTpl` 
                        &outertpl=`fuOuterTpl` 
        ]]
        <h2> Upload Icons</h2><br><br>
        [[!FileUpload?
                        &allowoverwrite=`1`                 
                        &filefields=`1` 
                        &createpath=`assets/media/icons/[[+modx.user.id]]`
                        &path=`assets/media/icons/[[+modx.user.id]]/` 
                        &extensions=`jpg,jpeg,png,gif` 
                        &messagetpl=`fuMessageTpl` 
                        &innertpl=`fuInnerTpl` 
                        &outertpl=`fuOuterTpl` 
        ]]
        <h2> Upload Extra Photo</h2><br><br>
        [[!FileUpload?
                        &allowoverwrite=`1` 
                        &filefields=`1` 
                        &createpath=`assets/media/extra/[[+modx.user.id]]` 
                        &path=`assets/media/extra/[[+modx.user.id]]/` 
                        &extensions=`jpg,jpeg,png,gif` 
                        &messagetpl=`fuMessageTpl` 
                        &innertpl=`fuInnerTpl` 
                        &outertpl=`fuOuterTpl`
        ]]
            <p> Only files with this extensions: ([[+fileupload.extensions]])</p>
            <div align="center"><input type="submit" value="[[+fu_upload_button_caption]]" /></div> 
        </form>
        </div>


        and my OuterTpl is:

        
                <input type="hidden" name="formid" value="[[+fileupload.formid]]" />
                <!-- MAX_FILE_SIZE must precede the file input field -->
                <input type="hidden" name="MAX_FILE_SIZE" value="[[+fileupload.maxsize]]" />
                [[+fu-inner]]
        
            


          MODx Version: 2.6.5-pl
          Developing in Local Page with:
          > MAMP 5.0
          > PHP 7.2.7
          • 54641
          • 10 Posts
          Here is my Output in the website sad The button don't works
            MODx Version: 2.6.5-pl
            Developing in Local Page with:
            > MAMP 5.0
            > PHP 7.2.7
            • 3749
            • 24,544 Posts
            Sorry, the more I think about it, the more I suspect that it can't work.

            Using multiple FileUpload tags will create multiple forms. Your button will only submit one of the forms at most (and the button will have to be inside a form to work).

            Using three separate outer TPL chunks where the first one contains the opening form tag and the third one contains the closing form tag (with no other form tags) would submit everything, but all three instances of the snippet will get the same array of files with no way to know which ones to put where.

            It might be possible to use to use just one FileUpload tag and put prefixes on the input field names so the snippet would know which files to put where (after removing the prefix), but you'd have to modify the FileUpload snippet code to do this, and to make it not use the inner TPL because you'd have created the fields yourself in outer Tpl. It wouldn't be easy and I'm not sure it's possible to make it work.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting