We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33655
    • 4 Posts
    I hope I’m posting this in the right place.

    I have a site that is up and running and am trying to add a simple php script that interacts with another database, a calendar, to one of the pages. The code runs fine from a static page with a .php extension. But, when I move the code to a snippet and then include the snippet in a page within the ModX framework, it no longer works.

    The site is rewriting the URLs to have .html extensions. So, I thought that might be the issue. So, I’ve added code to the .htaccess file to parse php in html pages. But, that didn’t have any effect.

    You can see the working version here...

    http://www.happilyeverlaughterparties.com/confirm.php

    Email: [email protected]
    Order#: 99999

    And, the snippet version...

    http://www.happilyeverlaughterparties.com/confirmation.html

    Any help would be much appreciated.

    Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      How are you calling the snippet? An interactive snippet like that needs to be called uncached. [!...!] for Evo, and [[!...]] for 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
        • 33655
        • 4 Posts
        That was it! Thank you!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          That’s because of how the parser more-or-less works. A snippet is evaluated (putting its code through the PHP eval() function) and its output is inserted into the page where the snippet tags were. If this output is a form, it will have the usual submit button and action attributes. Now, if that whole page, snippet and all, gets cached, when the submit requests the page again with the POST values from the form, there is no snippet code to process those POST values! All you’ll get is what was in the page when it was cached.

          An uncached snippet isn’t processed immediately; the page is processed and cached, then in a post-processing process a few odds and ends are cleaned up, including evaluating all uncached snippets. This post-processing is also performed on pages taken from cache, so the uncached snippet will get evaluated in all cases. Thus the re-requested page from the form’s action attribute will get its POST values processed.

          While Revo doesn’t use the PHP eval() function for snippet code (it writes the snippet code to a .php file and includes it) the cached/uncached feature has the same effect.
            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