We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11975
    • 2,542 Posts
    hi folks,

    I need help cause @EVAL drives me crazy.

    I’m trying to link two TVs. When the first has a value the second is feed with appropriate values.
    I’v eexperienced really odd behaviour. I can’t get it works both in the front and the back.
    The TV seems to be handled differently in the back and the front.

    You can test with this simple code
    create a TV (listbox) and paste this piece of code in input options values.

    @EVAL return $modx->getDocumentIdentifier('id');
    


    In the back office the ID is returned as expected but in the front the results is always the same : 1.

    Any idea.

    :-)
      Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
      • 11975
      • 2,542 Posts
      [*bump*]  tongue

      Still stuck in this issue.

      Isn’t there any solution to get the id of the document with @EVAL in the front end.

      any help greatly appreciated.

      thx.

      PS: by the way, why $modx->documentIdentifier is not available from @EVAL even if i’m adding global $modx;
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 11975
        • 2,542 Posts
        Ok, I think I’ve found the root of the issue

        In QE id is assigned to module ID and not id of the doc
        so as $modx->getdocumentIdentifier is based on the requested id I can’t get the doc value

        here is a part of QE rendered form


        <form id="tv_form" class="listbox-multiple" name="mutate" method="post" enctype="multipart/form-data" action="index.php">
        <input type="hidden" name="a" value="112" />
        <input type="hidden" name="id" value="2" />//this is the module id
        <input type="hidden" name="doc" value="9" />//this the doc id
        <input type="hidden" name="var" value="4" />
        <input id="save" type="hidden" name="save" value="1" />
        <input type="hidden" name="variablesmodified" value="">

        and the getDocumentIdentifier function in parser class

          function getDocumentIdentifier($method) {
            // function to test the query and find the retrieval method
            $docIdentifier= $this->config[’site_start’];
            switch($method) {
              case ’alias’:
                $docIdentifier= $this->db->escape($_REQUEST[’q’]);
              break;
              case ’id’:
               if(!is_numeric($_REQUEST[’id’])) {
                  $this->messageQuit("ID passed in request is NaN!");
                } else {
                  $docIdentifier= intval($_REQUEST[’id’]);
                }
              break;

            }
            return $docIdentifier;
          }

        EDIT: not sure that the form is involved I guess the error comes from QE but can’t find how to figure out this conflict with ’id’

        QuickEditor.js

        //in initialize

        this.moduleURL = managerPath+’index.php?a=’+this.moduleActionID+’&id=’+this.moduleID;

        open: function(contentID) {
          var url = this.moduleURL+’&doc=’+this.pageID+’&var=’+contentID;
          var name = ’QuickEditor-’+this.pageID+’-’+contentID;
          window.open(url, name, this.windowSettings);
        },

        ajaxSave: function(contentID, contentName, value) {

          var url = this.managerPath+’index.php?a=’+this.moduleActionID+’&id=’+this.moduleID+’&doc=’+this.pageID+’&ajax=1’;
          var params = new Array();
          params[’var’] = contentID;
          params[’tv’+contentName] = value;
          params[’save’] = 1;
          var param_string = $H(params).toQueryString();
         
          new Ajax.Request(url, {
           method:’post’,
           postBody:param_string,
           onSuccess: function() { window.location.reload(); },
           onFailure: function(request) { alert(request.responseText); }
          } );
          Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
          • 22303 MODX Staff
          • 10,725 Posts
          getDocumentIdentifier() is an internal method of the parser and is not meant for public usage. You want $modx->documentIdentifier or $modx->documentObject[’id’].
            • 11975
            • 2,542 Posts
            Using the methods you mentionned doesn’t return the doc id in frontEnd
            Neither in the backend.

            and don’t understand why huh

            thx for your help
              Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
              • 11975
              • 2,542 Posts
              Hi folks,

              After several attempts and a lot of endeavour, I’ve been able to achieve what I was looking for.

              feature:
              Link two TV to make the second display values according the choice made for the first one
              In my case, people choose beetwen: vegetables||fruits||meal||etc
              if TV1==fruits ==> TV2:apple||pear||etc

              Here is the solution:
              The main issue is to get the same result in the back and the front.
              The only way (according my skills) to detect is to check if QEditor is active or not.
              My first attempt was to get global values made by QE plugins but I didn’t succeed
              But modx is so great that you always have a way to get what you want.
              The solution is to create a snippet which will be called from the TV and who shares parameters with QE module based on dependencies
              In that case we will share $show_manager_link;
              so if show_manager_link is true we are on the front.

              SO let’s go:

              STEP 1 create your 2 TV

              TV1 (select single) = input options value : @SELECT name, id FROM ma_table ORDER by name ASC;
              TV2 (multiple select) = input options value : @EVAL return $modx->runSnippet(’createListOptions’);

              STEP 2 create a snippet "createListOptions"
              ADD this snippet to QE dependencies.
              ADD QE to the snippet dependencies (tab configuration)


              $value="Select first TV1==";

              $qeV = $show_manager_link;
              $pageID = ( $qeV == 1) ? $_REQUEST[’doc’] : $modx->getDocumentIdentifier(’id’);

              $pageID = ( $_REQUEST[’doc’]) ? $_REQUEST[’doc’] : $modx->getDocumentIdentifier(’id’);
              if(!empty($pageID)){
                  $templateTest = $modx->getTemplateVar(’templateTest’,’*’, $pageID);
                  if(strlen($templateTest[’value’])>0){
                      $sql= "SELECT aliment, idaliment FROM modx_aliments WHERE groupe=".$templateTest[’value’]." ORDER by aliment ASC";
                      $elt="";
                      $rs = $modx->db->query($sql);
                          while($myvalues = $modx->db->getRow($rs)) {
                          $elt .= $myvalues[’aliment’]."==".$myvalues[’idaliment’]."||";
                          }
                      $value = substr($elt,0,-2);
                     
                  }
              }


              return $value;

              :-)

              The behaviour is a bit chaootic for now, sometimes the value are not shown in backend , so still investigating.

              EDIT : I feel like an idiot smiley

              You don’t have to add dependencies
              We just have to check $_REQUEST[’doc’] which is the doc id in QE

              Now works fine

              hope that helps.

              PS/ I could not get from my snippet the current id with $modx->documentIdentifier or $modx->documentObject[’id’]
                Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: heliotrope at Sep 08, 2006, 08:36 AM

                PS/ I could not get from my snippet the current id with $modx->documentIdentifier or $modx->documentObject[’id’]
                That seems very odd. I use them in just about every snippet I’ve ever written and they work like a charm, though the documentObject use to not be available in some cases with cached documents. I’m not sure why you’re struggling with the issue, but getDocumentIdentifier() is an internal function of MODx, and not a public API, so it is not guaranteed to be available in future releases, while the variables documentIdentifier and the array documentObject are the proper ways to access the id of the document being rendered.

                There are potential pitfalls when using any component that passes a GET or POST variable called ’id’ -- perhaps this kind of conflict is what you are experiencing, but it’s not clear to me what problem you are having.
                  • 11975
                  • 2,542 Posts
                  Ths for your reply smiley

                  If you wish you can make the following test.

                  In a TV : @EVAL return $modx->runSnippet(’test’);

                  snippet ’test’:
                  return $modx->documentIdentifier;


                  I’ve also check $modx with print_r($modx)(result display in QE) and both [documentIdentifier] and [documentObject] are empty.

                  PS: I’ve also tried in the TV input options value field :
                  @EVAL $modx->documentIdentifier; without any result.
                    Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
                    • 22303 MODX Staff
                    • 10,725 Posts
                    I just put @EVAL return $modx->documentIdentifier; on a test document in the default content, in a Text TV called testdocid, and it rendered the current docID with no problem. I’m dumbfounded as to what problem you are experiencing, but I would imagine it either has to do with the way the TV’s are nested or with how the page/snippets are cached on that page. huh
                      • 11975
                      • 2,542 Posts
                      I must be an unlucky guy grin

                      Did your render the tv value in the Doc content in the front ??
                      In my case the @Eval is used to create options for a multiple select TV.

                      Anyway, if the getDocumentIdentifier function disappear I could get the id with $_REQUEST[’id’]
                      I don’t know why I haven’t thought earlier to check if ’doc’ was set to know where I was (backend or front end).

                      :-)
                        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l