We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36447
    • 98 Posts
    In my page template is a small custom form to capture names and email addresses for mail list signups.

    Upon form submission, I want the captured form variables to pass to a snippet for processing.

    How do I pass the collected form variables to my snippet?

    I’ve searched the forum but haven’t found the answer. Thx.
      • 22303 MODX Staff
      • 10,725 Posts
      Like you would in any PHP script, you access the request variables or GPC superglobals. $_GET for get values, $_POST for post values, $_COOKIE for cookie values, or $_REQUEST for an aggregation of the three which are merged based on a GPC order specified in the php configuration.
        • 36447
        • 98 Posts
        Thx for your response.

        So some kind of placeholder isn’t necessary, and the php script will recognize the passed form variables using $_REQUEST?

        Is it just snippets to snippets that require a placeholder?
          • 14050
          • 788 Posts
          Placeholders are generally used inside chunks and other general content fields.
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Placeholders are for displaying things generated dynamically on the actual page to be viewed. You can access them programmatically with the MODx api, but they don’t carry over from page to page. For that you need GET or POST or even using the SESSION or COOKIE to carry data over. I avoid REQUEST whenever I can, since it can leave things open for nasty people to override my values by messing with a cookie’s content, or adding stuff to the query string of the URL in their address bar. (and that’s why any kind of incoming data like that should be checked, double-checked, and then sanitized before using it for anything, like in a database query!)

            For example, in multiple language sites I’ll use a cookie to store the user’s language choice. I use a snippet to grab the language from the Cookie. That value gets used in a number of ways, such as determining which document to use as the parent for generating the menu, and which document to use as the "home" page on the site logo image, and setting parameters in other snippets to tell them which language file to include for forms and such. So it would make sense for my COOKIE-jar raiding snippet to be run right away, before anything else is done, and to set that value as a placeholder after making sure it’s the right kind of value ($modx->setPlaceholder(’language’, $language)), then wherever on the page I need it I can just use [+language+], instead of having to run the snippet to query the cookie over and over again.

            A snippet has to be run through the PHP eval() function every time, even if it’s for something as simple as that, while the placeholders are available as an array MODx sets up once for each page, and MODx replaces the placeholder with its proper value with a minimum of fuss and bother (otherwise known as server resources and time).

            But on the next page navigated to, the value has to be obtained from the COOKIE again, since the placeholder is only good for that one page.
              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
              • 36447
              • 98 Posts
              Thanks everyone for clearing up my confusion over placeholders, particularly Susan for her crystal-clear explanation, which I’m learning is her standard response after reading through the forum...