We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39085
    • 22 Posts
    I have the following form on a page named whatever.html, since I use the .html extension on my friendly URLs. The form submits to itself and is supposed to upload a file to a directory. If I have a page named whatever.php with the same code on it, it works fine. But as soon as I put the code in a MODX snippet and refer to it in a resource content, it fails. I have another similar form that has an empty action and it works fine to delete the files I previously uploaded. So I'm wondering if it is the action causing the problem, or if it the .html file extension on the page.

    The output for the attached code gives the form the following as its action:

    action="/index.php" [ed. note: bluemonkey3000 last edited this post 14 years, 6 months ago.]
      • 3749
      • 24,544 Posts
      If you want a form to submit to itself use this (I'm assuming your'e using Revolution):


      '<form action="[[~[[*id]]]]" method="POST" name="career_upload_form" id="career_upload_form" />'



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 39085
        • 22 Posts
        Thanks, Bob. That does work to get it the correct action='hr-career-management.html' which is the page itself. The problem still remains though. I'm not sure, but it seems like the PHP is not being processes once the form is submitted. I would assume is has something to do with the .html since .php gets processed at the server level. I'm not sure how MODX does it since all my friendly URLs end in .html. If I take the exact same code and place it in a .php page and then link to it via an iframe in the resource content, the PHP gets processed properly. But when I call the MODX snippet with the PHP code in it (exact same code again), the form gets properly echoed to the page, but does not get processed when the submit button in the form is clicked. So I know my PHP is correct... but it won't work in MODX.

        MODX Revolution 2.1.5
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You also need to call the form-processing snippet uncached.

          If it's cached, then the first time the page is generated the snippet is run, its output at that run is inserted into the page, and the whole page is cached. No more snippet tags. The next time the page is requested, it's served directly from cache. No snippet tags, no form processing.

          The same principle applies to any dynamic content, for example a snippet to display the current time. The snippet is run the first time the page is requested, the page is cached, and subsequent page loads are from cache. So until the whole cache is cleared, the time displayed won't change. If the snippet is uncached, the rest of the page is cached but the snippet tags are left intact. Now when the page is taken from cache, that left-over snippet is processed and inserted into the page before serving. The time will change on every page request, while the rest of the page can still benefit from not needing the full processing treatment.

          It's like adding fresh whipped cream to a piece of pie taken from the refrigerator rather than having to bake the whole pie from scratch every time you want a piece with whipped cream - or eat it without whipped cream.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 39085
            • 22 Posts
            That totally makes sense. But I do have the page settings in the resource set so that the Cacheable checkbox is not checked. Is this what you mean? Or is there something I'm missing in the PHP snippet itself?

            Thanks.
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              In any case, the .html extension doesn't mean anything, since every request to the server is re-written to the index.php file.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 39085
                • 22 Posts
                Thanks, that's good to know. At least I can rule that one out. It's funny how I can get it to work by simply putting the PHP from the snippet in an outside file and calling that in the action of the form. I may have to resort to that to get this thing working.
                  • 39085
                  • 22 Posts
                  Okay. So I figured it out.. to some extent. If I have the PHP snippet create my form that I want to use to upload a file to the server... it doesn't work. If I put the form in the resource and have the PHP parts created by the snippet, it works perfectly. The only issue was that the form is in the middle of the page surrounded by PHP, so I had to split my PHP up into two snippets: snippet1 followed by the form followed by snippet2... all on the resource page in the content.

                  Thanks everyone. I appreciate the guidance. And Bob, I still used the code you provided as this was the cleanest way to have the action refer to the current page.
                    • 3749
                    • 24,544 Posts
                    Glad you got it sorted. Any PHP in page content in MODX is ignored, so you have to move it all into snippets. You could put the form in a chunk and put a chunk tag between the two snippets.

                    You could definitely have the PHP code create the form, as long as there's no PHP code in the form.

                    You could also have the PHP code set a placeholder containing the form and put a placeholder tag on the page where you want the form to appear.


                    ------------------------------------------------------------------------------------------
                    PLEASE, PLEASE specify the version of MODX you are using.
                    MODX info for everyone: http://bobsguides.com/modx.html
                      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
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      That's why Formit is usually used for handling forms in Revo.
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org