We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6094
    • 60 Posts
    So, I am by no means proficient in PHP but I’m having to work my way through this in order to come up with a solution.

    I’ve create a form with dropdown options that will serve as a search form. For our purposes here I will set those as searchbox1, searchbox2 and searchbox3. Each of those selection boxes will have 3 values: value1, value2 and value 3. This form is located at searchform.com/form.html (not technically but this is all hypothetical anyway) and the results are passed in a querystring to searchform.com/results.html. So after the form values are selected the url would look something like searchform.com/results.html?searchbox1=value2&searchbox2=value1&searchbox3=value3. I’m sure you all get the point.

    I’ve created a snippet that loads variables for each of the values from the querystring. So now I have $searchboxvalue1, $searchboxvalue2 and $searchboxvalue3.

    Now I need to know if it’s possible to use getresource to load a chunk that displays data based on the value of a custom TV that equals the value of one of my variable? Well actually 3 different variables corresponding to 3 different TV’s. Like I said I’m kind of stumbling through this and there may be a better way of doing this than what I’m aware of so any help is greatly appreciated.
      • 3749
      • 24,544 Posts
      I sounds like it might not be that complicated, but we need more information about what you’re trying to do.

      Would getResources be displaying more than one document at a time ? (If not, you probably don’t need getResources.).

      Can you tell us how the searchbox values are intended to affect the output (e.g., do you just want to know if they’re empty or not)?

      Do you need to store the searchbox values semi-permanently, or you just need them to tailor the display?

      Are (or can) the searchbox values be constrained so that you know what the possibilities are ahead of time?
        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
        • 6094
        • 60 Posts
        It seems like it may be simple to me as well. Let me see if I can answer your questions.

        I’m not exactly sure what your asking in regards to getResources and more than one document. Technically, it will be pulling from a chunk that is set to display data from more than one page. So technically I guess the answer is yes.

        In regards to question 2. The values in theory are parsed against the TV. If they are equal to a TV value then display, if not then ignore.

        Yes, the searchbox values are really only needed temporarily for determining a value.

        Yes, the searchbox values are constrained within a dropdown selection. Only one value selected, with predefined options.

        I haven’t tested it yet to see if it meets my needs, but after searching I came across this entry and it may work for what I’m trying to do.
        http://modxcms.com/forums/index.php?topic=57991.0

        Quote from: BobRay at Dec 28, 2010, 01:35 PM

        I sounds like it might not be that complicated, but we need more information about what you’re trying to do.

        Would getResources be displaying more than one document at a time ? (If not, you probably don’t need getResources.).

        Can you tell us how the searchbox values are intended to affect the output (e.g., do you just want to know if they’re empty or not)?

        Do you need to store the searchbox values semi-permanently, or you just need them to tailor the display?

        Are (or can) the searchbox values be constrained so that you know what the possibilities are ahead of time?

          • 3749
          • 24,544 Posts
          I’m afraid I don’t understand this:

          a chunk that is set to display data from more than one page.

          What’s in the chunk and how does it display data from different pages? Feel free to post the chunk.

          Also, will the TV values change over time, or are they fixed?
            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
            • 6094
            • 60 Posts
            This would be the chunk titled floorplanDisplay:

            <div class="albumContainer">
                        <div class="albumImageBlock">
                             <a href="[[+id]]"><img src="[[+tv.planImage:phpthumbof=`w=150&h=150`]]" alt="[[+pagetitle]] Floorplan" border="0" class="galleryThumbImg"/></a>
                        </div> 
                        <div class="albumContentBlock">
                          <p class="albumContainerHeader"><a href="[[+id]]">[[+pagetitle]]</a></p>
                          <p>[[+tv.sqft]] Sq. Ft., [[+tv.beds]] bedrooms, [[+tv.baths]] bathroom(s)</p>
                        </div>
                        <div class="clear"></div>
            </div>
            


            These are the three snippets created from the query string passed by the search form:
            <?php
            /*    searchQuery
                  [[!searchQuerySQFT]]
            
            */
            $SQFT = '';
            $SQFT = $_GET['squarefootage'];
            echo $SQFT';
            ?>
            


            <?php
            /*    searchQuery
                  [[!searchQueryBeds]]
            
            */
            $beds = '';
            $beds = $_GET['beds'];
            echo $beds';
            ?>
            


            <?php
            /*    searchQuery
                  [[!searchQueryBaths]]
            
            */
            $baths = '';
            $baths = $_GET['baths'];
            echo $baths';
            ?>
            


            Now my assumption is that I could make the following call and it should work:
            [[!getResources? &parents=`20` &tpl=`floorplansDisplay` &includeTVs=`1` &processTVs=`1` &limit=`0` &includeContent=`1` &depth=`0` &sortby=`id` &sortdir=`ASC` &tvFilters=`beds==[[!searchQueryBeds]],baths==[[!searchQueryBaths]]`]]
            


            I recently made an edit to this post after testing. This seems to work, however I haven’t tried adding filters above two at this point.

            I’m also curious how to display a message if there are no records returned? Say there are no pages that meet the criteria searched as it stands it just displays a blank page.

              • 3749
              • 24,544 Posts
              I could be wrong, but I think there are two separate ways to go and you’re kind of going in both directions at once.

              1. Have a separate resource for each house with TVs for the sq feet, br’s, path to image, etc. The data is stored in the TV’s, no snippet necessary except for searching, and getResources should be able to do it either out-of-the-box, or with a custom filter.

              2. (This is much more efficient and is definitely the way to go if you’ll have a lot of houses and/or a lot of visitors to the site).
              - Keep *all* the data for each house in a custom DB table (preferably set up to work with xPDO), with one row for each house.
              - In your snippet, which can be on the search page activating only on submission:
              - Query the DB based on the search form
              - If there are no results, get the "No Results" Tpl Chunk and return it.
              - Get the "House" Tpl chunk with $modx->getChunk()
              - Iterate through the results, using str_replace() to replace the placeholders in the chunk, adding the result to the $output variable.
              - return the $output.

              That part of the snippet would look something like this (I’m using an xPDO example where each house is an xPDO object -- easier than it looks):

              <?php
              /* test for postback status here */
              $output = $modx->getChunk('SearchHeaderTpl');  // Anything you want at the top of the results page.
                                                                                                          // Might have placeholders for the search criteria
                                                                                                          // e.g., "you searched for: 3+ BR, etc.
              
              if ($isPostback) {
                  /* query the DB with getCollection() based on the search criteria set in $c */
              
              $houses = $modx->getCollection('modHouse',$c);
              
              if (empty($houses) ) {
              
                $output .= $modx->getChunk('NoResultsTpl');
              
              } else {
                 $tpl = $modx->getChunk('houseTpl');
              
                 foreach ($houses as $house) {
                     $tpl = str_replace('[[+squareft]]', $house->get('squareft'), $tpl);
                     $tpl = str_replace('[[+bedrooms]]', $house->get('bedrooms'), $tpl);
                    /* etc. */
                    $output .= $tpl;
                 }
              }
              
              return $output;
              
              }







              }
                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
                • 6094
                • 60 Posts
                Wow, I have no doubt that your xPDO option is the way to go. However, I am still very much a newb at this and that is well beyond my understanding as of right now. I guess it’s time to crack the documentation on xPDO.
                  • 3749
                  • 24,544 Posts
                  Quote from: ctownsend at Dec 29, 2010, 12:04 PM

                  Wow, I have no doubt that your xPDO option is the way to go. However, I am still very much a newb at this and that is well beyond my understanding as of right now. I guess it’s time to crack the documentation on xPDO.

                  I agree. Since you already have the table (right?), this should get you started:

                  http://bobsguides.com/custom-db-tables.html


                  Once you get a taste of xPDO, you never want to go back. wink
                    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