We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33311
    • 11 Posts
    Hi, i been trying this for a wholebut i can’t seems to get the variable from ditto and use it in my snippet.

    for example i have a ditto call in a drop-down menu; which will fill the option in the drop-down

    <select name="department">
    [!Ditto? &amp;parents=`25` &amp;display=`all` &amp;depth=`5` &amp;filter=`id,47,2|id,50,2|id,53,2` &amp;summarize=`10` &amp;tpl=`position_option_list` &amp;noResults=`no_positon_option_list`!]
    </select>

    which then call a chuck "position_option_list"

    <option [[isSelect]] >[+pagetitle+]</option>

    and then called the snippet [[isSelect]]

    <?php
    $idx= ’[+id+]’;
    $pId= @$_GET["postid"];

    if ($pId == $idx){
    echo "SELECTED";
    }else{
    echo "NO";
    }
    ?>

    which compare the id it retrieve from the ditto, and the variable id i place in the url, and put a "SELECTED" on the option.

    if i put echo $idx, it display the id correctly;

    but somehow when i use it to compare the $pid & $idx, it always becomes False;

    i notice that if i try

    echo $idx+100;

    the $idx value becomes zero and instead it echo as "100". The value doesn’t seems to hold in the variable


    What am i doing wrong here?

      • 3749
      • 24,544 Posts
      I can’t really tell what you’re trying to do but first, you need to change &amp; to just & in the snippet call. TinyMCE is trying to be helpful and encoding the &s. The quickest fix it to turn off the Rich Text Editor.

      Second:

      if i put echo $idx, it display the id correctly;

      but somehow when i use it to compare the $pid & $idx, it always becomes False;

      i notice that if i try

      echo $idx+100;
      the $idx value becomes zero and instead it echo as "100".

      I honestly don’t see how this it possible unless you’ve misspelled $idx somewhere or your version of PHP has a really serious bug in it.

      Third, What happens when you echo $pId? And are you sure you’ve spelled it $pId everywhere (not $pid as you spelled it in your message).
        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
        • 33311
        • 11 Posts
        Ok, This is what i was trying to accomplish; i have a parent with a list of available jobs. If i click on one of the job( say "System Enginner"), it will bring me to another document called "System Enginner". In this document there is a "Apply now" link. If i click on this link it will direct the user to an application form. In the application form, which uses eForm, it has a drop down option, with the list of all the available job position from the parent.

        eg

        <select>
        <option>Manager</option>
        <option>System Engineer</option>
        </select>

        What i wanted to do was to have the option automatically select "System Engineer", based on the previous page i click "Apply Now" link from.

        So far i manage to get the ditto to show all the available job position dynamically correctly. But i can’t seems to get it to automatically select the job "System Engineer"

        What i did was this;

        in the Apply Now link, i added a postid variable of the current document ID;

        it will then go to the application form

        eg:

        http://web/ff/index.php?q=63.html&postid=51

        In the application form, i have a snippet that will grab the postid value and put it into $pId. It will also get the ditto [+id+] from the current ditto and put it into $idx. It then compare both value,if it match then it will put a "SELECTED" text into the <option> .

        This is the snippet;

        <?php
        $idx= ’[+id+]’;
        $pId= @$_GET["postid"];

        if ($pId == $idx){
        echo "SELECTED";
        }else{
        echo "NO";
        }
        ?>

        in both variable they seems to be able to retrieve the value correctly. I did an echo on both variable and it show the value correctly in the browser;

        but somehow, even thought value of both variable matches, it doesn’t return TRUE.

        i did more digging,

        and what i notice was the value $idx was acting wierd. For example

        if i type

        echo $idx;

        the value come out correctly eg: 51,

        but if i did some maths like this:

        echo $idx+100;

        the value shows 100 and not 151; its as if $idx value dissappeared and became 0.

        So somehow the value for $idx from ditto just dissappear when i try to use it.

        Any idea?







          • 36592
          • 970 Posts
          I’m not a programmer but... I think...
          $idx= '[+id+]';

          This is not good. You’d better give value as a parameter like...
          &idx=`[+id+]`
            • 33311
            • 11 Posts
            no that didn’t work also.

            anyway i don’t think its &idx= as "&" gives me an error;
              • 4172
              • 5,888 Posts
              tkfm is right:
              he means your call:
              [[isSelect? &idx=`[+id+]`]]


              your snippet:

              <?php
              
              $pId= @$_GET["postid"];
              
              return ($pId == $idx)?'selected="selected"':'';
              
              ?>
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 33311
                • 11 Posts
                Ah Nice. It works. Thanks TKFM, Bruno.