We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32645
    • 377 Posts
    I have built a custom library which sits outside of MODX, everything is put into an output field, then saved to a Placeholder such as:

    $modx->setPlaceholder("searchResults", $output);
    


    However, if I go to a chunk and put:

    [+searchResults+]
    


    Or even in another snippet I put:

    echo "[+searchResults+]"
    


    Nothing ever appears.

    If however I put:

    print $modx->getPlaceholder("searchResults");
    


    This works --- however it is restricted to the snippet -- almost as if its a local variable.

    if I want to use this placeholder in another snippet, chunk, or whatever it doesn’t work.

    How do I make setting placeholders a global event that I can use elsewhere?



      • 22303 MODX Staff
      • 10,725 Posts
      This is going to depend entirely on execution order and the cacheability of the page.
        • 32645
        • 377 Posts
        Oh I see.

        I’m using it on an Eform, so that:

        [!eventFunctionSnippet!]
        [!eForm? &eFormOnBeforeFormParse=`formParseEvent`  &eFormOnBeforeMailSent=`formParseResults` &formid=`HSF` &tpl=`simple_form` &noemail=`0` &debug=`1`!]
        


        and then in the formParseEvent function I create the placeholder, but I can’t seem to use it in formParseResults.

        ie:

        <?php
        //search-results
        function formParseResults( &$fields, &$templates )
        {
                global $modx, $vMsg;
        
               // this should be outputting the search results;
               print ( $modx->getPlaceholder('holidaySearchResults') );
        }
        
        function formParseEvent( &$fields, &$templates, $debug=false )
        {
        	global $modx, $vMsg;
                $debug = false;
        	if ($debug == true)
                {
        	print '<pre>GET: '. print_r($_GET) . '</pre>';
        	print '<pre>POST:'. print_r($_POST) . '</pre>';
        	print '<pre>FIELDS: '. print_r($fields) . '</pre>';
        	print '<pre>vMsg: '. print_r($vMsg) . '</pre>';
        	print '<pre>rMsg: '. print_r($rMsg) . '</pre>';
                print '<p>' . $modx->getPlaceholder('validationmessage') . '</p>';
                }
        	
                $output = '';
        	$basePath  = $modx->config['base_path'];
        	$siteURL	   = $modx->config['site_url'];
        
        	include_once( $basePath .'assets/snippets/curl/holiday.php' );
        
        	$Holiday = new Holiday(&$modx);
                $sarray = $Holiday->processForm();
                $outcome   = $Holiday->build_sql($sarray);
          
               // set the placeholder
               $modx->setPlaceholder('holidaySearchResults', $outcome );
        
        // if I output the placeholder here it works fine... I just can't seem to output anywhere else...
        
        return true;
        } // end function
        ?>
        


        I hope this clarifies what I’m trying to do.
          • 3749
          • 24,544 Posts
          If you can’t get setPlaceholder() and getPlaceholder to work, you can replace them with a $_SESSION variable for each placeholder.

          $val = "hello"
          
          /* instead of setPlaceholder() */
          
          $_SESSION['my_variable'] = $val;
          
          
          /* in the other snippet, in place of getPlaceholder() */
          
          $mySetting = $_SESSION['my_variable'];
          
          $modx->setPlaceholder('myplaceholder', 'mySetting' ); // if you still need to set a placeHolder
            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
            • 22303 MODX Staff
            • 10,725 Posts
            Then that is an eForm issue, not a core code one. eForm does processing in a very specific way and you’ll need to probably get help in the forum dedicated to that component.
              • 32645
              • 377 Posts
              I understand. I’ll close this thread.

              I did a test with a basic form without using EForm and then using a snippet to catch post/get variables -- and you are correct about the issue, as I was easily able to create placeholders in my snippet without any issue.

              I’ve decided just to custom build my way out of the problem.

              **THREAD CLOSED***
                • 7231
                • 4,205 Posts
                Late to the party here but the way to do this in eForm is to add the variable to the $fields array by simply using $fields[’customVar’] = "your value";

                Then in the report and thankyou it will available as [+customVar+].

                See the documentation example at /assets/snippets/eform/docs/eform_example_events.htm
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 32645
                  • 377 Posts
                  It doesn’t matter now, I did my own solution with a custom built library which sits outside of MODX.