We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hey guys,

    Anyone knows how to retrieve an internal document’s referrer ID in Revolution?

    I can retieve the referrer url with simple JavaScript using this code:

    <script type="text/javascript">
    document.write(document.referrer);
    </script>


    And how about some other placeholders like pagetitle, longtitle etc.?

    I’m on Revolution 2.0.5 // PHP 5.2.12 // MYSLQ 5.0.67
      A MODx Fanatic
      • 3749
      • 24,544 Posts
      There may be an easier way, but you could have a snippet in your template that saves that info to one or more $_SESSION variables and another snippet (above the first one) that uses those $_SESSION variables to set placeholders that would then be available in the page to display them.
      [[!GetReferer]]
      [[!SetReferer]]
      
      <p>Referer Page Title: [[+ref.pagetitle]]</p>
      

      <?php
      /* GetReferer snippet */
      $modx->setPlaceholder('ref.pagetitle',$_POST['referer_pagetitle']);
      


      <?php
      /*SetReferer snippet */
      $_POST['referer_pagetitle'] = $modx->resource->get('pagetitle');
        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
        • 30585
        • 833 Posts
        Thanks Bob. This is definitely gonna save me great time and sweat.

        Here’s what I have in mind and hopefully you can help me figure this out:

        I have a blank print-friendly document that I’m hoping to use to print documents.

        On any given document, when a user clicks the print button (custom), the print-friendly document mentioned above will be loaded in a new tab with the referring document’s information.

        I’m hoping to use your snippets with another great one: getResourceField to make this possible.

        The print-friendly page would look something like this one:

        [[!GetReferer]]
        <html>
          <head>
          <title>[[getResourceField? &id=`[[+ref.id]]` &field=`pagetitle` ]]</title>
          </head>
          <body>
          <h1>[[getResourceField? &id=`[[+ref.id]]` &field=`longtitle` ]]</h1>
          [[getResourceField? &id=`[[+ref.id]]` &field=`content` ]]  
          </body>
        </html>
        



        I understand that I need to tweak your snippets so I can retrieve the referriung doc’s ID instead of of the page title.
        But Once I’ve done that, should I place the [[!GetReferer]][[!SetReferer]] calls only on all other pages except the print-friendly?

        Last question, do I still need to place the [[!SetReferer]] on the blank page, even if I don’t want it being tracked?

        Thanks
          A MODx Fanatic
          • 3749
          • 24,544 Posts
          In that case, I think I’d just put the necessary information in hidden fields in the form with the button and make the method "post"

          Something like this:

          <form action="url/of/print/page" method = "post" />
              <input type="hidden" name="pageId" value="[[*id]]" />
              <input type="hidden" name="pageTitle" value="[[*pagetitle]]" />
              <input type="Submit" name="Submit" value="submit />
          </form>


          Then you can use $_POST[’pageId’] and $_POST[’pageTitle’] in a snippet on the print page.

          In that snippet, you’d set placeholders with the document’s fields:
          <?php
          /* SetPlaceholders snippet */
          if (! empty($_POST['pageId']) ) {
              $resource = $modx->getObject('modResource',$_POST['pageId']);
              if ($resource) {
                  $modx->setPlaceholder('MyPagetitle',$resource->get('pagetitle'));
                  $modx->setPlaceholder('MyLongtitle',$resource->get('longtitle'));
                  $modx->setPlaceholder('MyContent',$resource->getContent()); // notice this one is a little different
              }
          }
          return '';
          


          On your print page:

          [[!SetPlaceholders]]
          <html>
            <head>
            <title>[[+MyPagetitle]]</title>
            </head>
            <body>
            <h1>[[+MyLongtitle]]</h1>
            [[++MyContent]]  
            </body>
          </html>


          Or, you could set all the necessary fields in the form, skip the getObject() call, and just use the $_POST values.
            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
            • 30585
            • 833 Posts
            Bob, you and the rest of the core team make MODx the user-friendly and limitless system it truly is.

            Sorry for the hype, but I had to do it.

            Thanks man.
              A MODx Fanatic
              • 30585
              • 833 Posts
              Hey Bob --

              Sorry, one last question. The snippet is producing parsing error:


              Parse error: syntax error, unexpected ’;’ in /var/www/vhosts/website.info/httpdocs/core/cache/elements/modsnippet/65.include.cache.php on line 9

              I opened the 65.include.cache.php file to check it and didn’t see any particular problem with the snippet except I found this.
              <?php  return 'function elements_modsnippet_65($scriptProperties= array()) {
              global $modx;
              if (is_array($scriptProperties)) {
              extract($scriptProperties, EXTR_SKIP);
              }
              /* SetPlaceholders snippet */
              $resource = $modx->getObject(\'modResource\',$_POST[\'pageId\']);
              $modx->setPlaceholder(\'MyPagetitle\',$resource->get(\'pagetitle\');
              $modx->setPlaceholder(\'MyLongtitle\',$resource->get(\'longtitle\');
              $modx->setPlaceholder(\'MyContent\',$resource->getContent()); // notice this one is a little different
              return \'\';
              }
              ';

              The backslashes were added automatically. This is my original qupte:
              <?php
              /* SetPlaceholders snippet */
              $resource = $modx->getObject('modResource',$_POST['pageId']);
              $modx->setPlaceholder('MyPagetitle',$resource->get('pagetitle');
              $modx->setPlaceholder('MyLongtitle',$resource->get('longtitle');
              $modx->setPlaceholder('MyContent',$resource->getContent()); // notice this one is a little different
              return '';


              Do you see what’s wrong?
                A MODx Fanatic
                • 3749
                • 24,544 Posts
                It looks like magic_quotes_gpc in action. http://php.net/manual/en/security.magicquotes.disabling.php

                It may be a side effect of pasting from the board, or a problem with your setup.

                If you can’t turn magic_quotes_gpc off, you could try pasting the original code into something dumb like notepad, then copying it again to MODx.
                  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
                  • 30585
                  • 833 Posts
                  Quote from: BobRay at Dec 15, 2010, 11:30 AM

                  It looks like magic_quotes_gpc in action. http://php.net/manual/en/security.magicquotes.disabling.php

                  It may be a side effect of pasting from the board, or a problem with your setup.

                  If you can’t turn magic_quotes_gpc off, you could try pasting the original code into something dumb like notepad, then copying it again to MODx.


                  Hey Bob, I did paste the code from plain text and magic_quotes_gpc is set to off. Here’s what phpinfo() returns:
                  magic_quotes_gpc	Off	Off
                  magic_quotes_runtime	Off	Off
                  magic_quotes_sybase	Off	Off
                  

                  Anything else? This is the first time I get this type of issue by the way.

                  Thanks.
                    A MODx Fanatic
                    • 3749
                    • 24,544 Posts
                    I looked at my cached snippets and some of them look like that too.

                    Sorry, the second and third lines are missing a closing parenthesis at the end. I make this mistake all the time when I’m entering code in a hurry -- my editor closes them automatically but I’m not in it here. tongue

                    It should be:

                    <?php
                    /* SetPlaceholders snippet */
                    if (! empty($_POST['pageId']) ) {
                        $resource = $modx->getObject('modResource',$_POST['pageId']);
                        if ($resource) {
                            $modx->setPlaceholder('MyPagetitle',$resource->get('pagetitle'));
                            $modx->setPlaceholder('MyLongtitle',$resource->get('longtitle'));
                            $modx->setPlaceholder('MyContent',$resource->getContent()); // notice this one is a little different
                        }
                    }
                    return '';
                    
                      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
                      • 30585
                      • 833 Posts
                      Great!

                      This is working like a charm except I get the following error in the source code:


                      <br /> 
                      <b>Fatal error</b>:  Call to a member function get() on a non-object in <b>/var/www/vhosts/website.info/httpdocs/core/cache/elements/modsnippet/65.include.cache.php</b> on line <b>9</b><br /> 


                      The 65.include.cache.php file has this:
                      <?php
                      function elements_modsnippet_65($scriptProperties= array()) {
                      global $modx;
                      if (is_array($scriptProperties)) {
                      extract($scriptProperties, EXTR_SKIP);
                      }
                      /* SetPlaceholders snippet */
                      $resource = $modx->getObject('modResource',$_POST['pageId']);
                      $modx->setPlaceholder('MyPagetitle',$resource->get('pagetitle'));
                      $modx->setPlaceholder('MyLongtitle',$resource->get('longtitle'));
                      $modx->setPlaceholder('MyContent',$resource->getContent()); // notice this one is a little different
                      return '';
                      }
                      


                      Does this mean that getObject shouldn’t be used?

                      I know this is becoming a pain and I’m sorry about that.
                        A MODx Fanatic