We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    One caveat here:

    Be wary of collisions and always use a name for your $_REQUEST variable that is very likely to be
    unique (i.e., not "resource" or "filename").



    ------------------------------------------------------------------------------------------
    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
      • 39932
      • 483 Posts
      I thought I had mentioned this, but after reviewing, realized that I had not. A great way to send temporary data is to use a MD5 hash of some unique property that you control and append the fieldname to it. This would be your $_REQUEST array key. This makes it unlikely to ever be reproduced. It doesn't have to be overly complex... remember it is only in use for one URL request.

      A poor example (really, don't use User ID):
      $prekey = $modx->user->get('id');
      $key = md5($key);
      $field = 'fieldname';
      $key = $key . $field;
      
      $_REQUEST[$key] = 'myValue';
      


      To get:

      $prekey = $modx->user->get('id');
      $key = md5($key);
      $field = 'fieldname';
      $key = $key . $field;
      
      $getValue = $_REQUEST[$key]
      

        Website: Extended Dialog Development Blog: on Extended Dialog
        Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
        Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

        Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
        • 40553
        • 42 Posts
        Great! I finally understood the concept and hope I will be able to achieve the desired result. Thank you for all the suggestions!
          • 40553
          • 42 Posts
          Old topic comes back again...There is no way I can get the calue of the $_REQUEST in one snippet if its value was defined in another. Tried all sorts of solutions and the presented solutions from above work only if the value is set and retrieved in the same snippet. Any ideas?

          Even the simplest concept does not work:

          One snippet sets the request - $_REQUEST['test'] = 'test info';
          Another snippet gets the request value - $var = $_REQUEST['test']; return $var;
          Both snippets are uncached and are on the very same page.

          What is more interresting, setting and getting placeholder works in a weird way:

          Let's assume I set a placeholder in one snippet the follwoing way:
          $modx->setPlaceholder('placeholder_name', $var);

          and afterwards I'm unable to retrieve it in the otther snippte using this code:
          $modx->getPlaceholder('placeholder_name');

          but I'm able to output its value using [[+placeholder_name]]

          That really does not make sense to me or maybe I don't know some snippet processing mechanisms in MODX... [ed. note: ellipsis_89 last edited this post 14 years ago.]
            • 3749
            • 24,544 Posts
            Have you tried using $_SESSION variables?

            $_SESSION['test'] = 'test info';
            
            $var = $_SESSION['test']; return $var;
            


            BTW, the tag for the snippet that sets the value has to come earlier on the page than the tag for the one that gets it.


            ------------------------------------------------------------------------------------------
            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
              • 18373 ☆ A M B ☆
              • 3,141 Posts
              $modx->getPlaceholder('placeholder_name');

              That should work in the other snippet as well. If it's not there, it might be that the snippet that sets it is processed *after* the snippet you are trying to fetch it with.

              If that is the case, $_REQUEST, $_SESSION or whatever will not work either - it's just the processing order that is causing your issue.

              In general: cached tags are executed before uncached tags, and it follows the source order in (most) other cases.

              Also, if you use $modx->setPlaceholder, you will be able of just using the placeholder [[+notification]] or [[!+notification]] elsewhere - taking into account the parsing/processing order, that is.
                Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                • 40553
                • 42 Posts
                Thank you for your suggestions. According to the suggestions of Mark Hamstra, my set/get placeholder implementation shouldn't work since I output the value in meta <title> tag whereas the snippet is placed in body. It actually works, if I set the placeholder programatically and output it's value using the following code:
                [[+placeholder_name]]

                but it doesn't work if I put the following code in the snippet and place it in the title tag:
                $modx->getPlaceholder('placeholder_name');


                Then my question is how these methods are different from one another?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Is that the entire snippet code, or do you actually output the value?
                  $output = $modx->getPlaceholder('placeholder_name');
                  return $output;
                  
                    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
                    • 4172
                    • 5,888 Posts
                    This has todo with order of parsing.
                    The parser runs multiple times over the code.

                    This means for your scenario, your snippet sets the placeholder in one step, in the next step, modx replaces your placeholder with this value.

                    When you replace the placeholder with a snippet-tag, modx runs the snippets in the order as its in your template and replaces its tags with the result, but the first snippet doesn't know anything about the placeholder, you will set on the second snippet.
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 40553
                      • 42 Posts
                      Well I get and output the placeholder value the way you stated in your post:
                      $output = $modx->getPlaceholder('placeholder_name');
                      return $output;

                      Still the getPlaceholder function doesn't work, not at all...The only case it works is when it's set and get in the same snippet. The orderd of snippets did not solve the problem