We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Revo 2.5.2

    I have a picker that displays 3 top-level (folder) options: Folder A (id 2), Folder B (id 3) and Folder C (id 4) respectively.
    <select data-placeholder="Search..." name="parent" id="parent">
    <option></option>
    [[!getResources?
    	&parents=`0`
    	&tpl=`Search Option`
    	&where=`{"isfolder:=":"1"}`
    	&sortby=`alias`
    	&sortdir=`ASC`
    	&depth=`0`
    	&includeContent=`1`
    ]]
    </select>

    <option[[!getReqParam:is=`[[+id]]`:then=`selected="selected"`:else=``? &name=`parent`]] value="[[+id]]">[[+pagetitle]]</option>

    The search results (or lack thereof) are shown on a different resource. For no (empty) results the sisea.no_results message returns this:
    <p>The term [[+query]] can’t be found.</p>

    It works fine.

    To this message I would like to pass the name of the resource selected in the picker, e.g. Folder C.

    I've tried UltimateParent, getResourceField and rootResource without luck.

    This question has been answered by BobRay. See the first response.

      Todd
      • 3749
      • 24,544 Posts
      Did any of the things you tried return the ID of the selected folder?
        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
        • 40088
        • 708 Posts
        No id, no nothing.
          Todd
          • 3749
          • 24,544 Posts
          If I'm understanding you, you have a form where the user selects the search term, and a snippet that processes the results on a separate page.

          On that second page, you should be able to capture the Name from the $_POST or $_GET array (depending on the method in the form tab).

          If the form method is get, is there anything to identify the parent in the URL of the second page?
            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
            • 40088
            • 708 Posts
            Correct, the results are processed on a different page.

            Yes, the form method is get and yes the parent id is part of the results page url. For example, if I search Folder A (id 2) for the term "modx" here's the (partial) url:
            ?parent=2&search=modx&id=21

            Here's the entire search form:
            <form action="[[~[[+landing:default=`[[*id]]`]]]]" method="[[+method:default=`get`]]">
            	<fieldset>
            		<select data-placeholder="Search..." name="parent" id="parent">
            			<option></option>
            [[!getResources?
            	&parents=`0`
            	&tpl=`Search Option`
            	&where=`{"isfolder:=":"1"}`
            	&sortby=`alias`
            	&sortdir=`ASC`
            	&depth=`0`
            	&includeContent=`1`
            ]]
            		</select>
            		<input type="text" name="[[+searchIndex]]" id="[[+searchIndex]]" value="[[+searchValue]]">
            		<input type="hidden" name="id" value="[[+landing:default=[[*id]]]]">
            		<input type="submit" value="[[%sisea.search? &namespace=`sisea` &topic=`default`]]">
            	</fieldset>
            </form>
              Todd
              • 3749
              • 24,544 Posts
              Try this on the second page:

              Put this where you want the pagetitle:

              [[!GetTitle]


              Then create a GetTitle snippet with this code:

              <?php
              $fields = array('name' => 'id');
              $docId = (int) $modx->runSnippet('getUrlParam', $fields);
              
              $query = $modx->newQuery('modResource', $docId);
              $query->select('pagetitle');
              return $modx->getValue($query->prepare());
              


              There is a tiny security issue here. A user can get the pagetitle of any page by manually altering the id in the URL, but I can't see much potential harm there. They can also get a list of links under any parent (including 0). If that's a problem, you can check the ID and forward them to the home page if it's not legit. [ed. note: BobRay last edited this post 7 years, 4 months ago.]
                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
                • 40088
                • 708 Posts
                Using the code above the results page is completely blank (white).
                  Todd
                  • 3749
                  • 24,544 Posts
                  Typo again. Delete line 6 -- ));
                    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
                    • 40088
                    • 708 Posts
                    Hmmm... now it returns the id of the results page, not the name of the selected folder being searched.

                    Coincidently this is also the same result I got with UltimateParent, getResourceField and rootResource. [ed. note: todd.b last edited this post 7 years, 4 months ago.]
                      Todd
                      • 3749
                      • 24,544 Posts
                      Try:

                      $fields = array('name' => 'parent');
                        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