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

Answered Searching MIGXdb

    • 30734
    • 44 Posts
    Hello! I have been having some troubles getting search functionality working with MIGXdb and BloX. I have been following the tutorials at: http://www.bdcreative-design.com/blog/data-from-the-migxdb-cmp/

    I have been able to get the data to show up on a page with BloX, but now that I am attempting to put together a multifield search for this property listing system I am running into problems.

    I have 3 items I need to search, Property Type, Property Location, and if it is for Lease or Purchase. Below is my Form code, config, and my BloX calls. Right now when I select my search terms and hit search the page just reloads without going the the search results page. Please let me know if im missing something obvious.

    Form Tpl
    <div id="search_container">
    <form action="[[~21]]" method="get" name="search" class="clearfix">
    <h2>Seach</h2>
    <fieldset id="form_type">
    <select name="proptype">
    <option value="Office">Office</option>
    <option value="Industrial">Industrial</option>
    <option value="Retail">Retail</option>
    <option value="Multifamily">Multifamily</option>
    <option value="Land">Land</option>
    </select><br/><br/>
    
    <select name="proploc">
    <option value="Metro Area">Metro Area</option>
    <option value="Arapahoe County">Arapahoe County</option>
    <option value="Adams County">Adams County</option>
    <option value="Jefferson County">Jefferson County</option>
    <option value="Arvada">Arvada</option>
    <option value="Aurora">Aurora</option>
    <option value="Centennial">Centennial</option>
    <option value="Denver">Denver</option>
    <option value="Lakewood">Lakewood</option>
    <option value="Littleton">Littleton</option>
    <option value="Westminister">Westminister</option>
    <option value="Wheat Ridge">Wheat Ridge</option>
    </select><br/><br/>
    
    <input type="radio" name="propfor" value="Lease"> Lease OR <input type="radio" name="propfor" value="Purchase"> Purchase<br/><br/>
    
    </fieldset>
    <input type="submit" value="Search" name="searchButton" />
    </form>
    </div>


    propsearch.config.inc.php
    <?php
    $proptype = $modx->getOption('proptype',$_REQUEST,'');
    $proploc = $modx->getOption('proploc',$_REQUEST,'');
    $propfor = $modx->getOption('propfor',$_REQUEST,'');
     
    $wheres = array();
    if (!empty($proptype)){
        $wheres[] = array('proptype' => $proptype);
    }
     
    if (!empty($proploc)){
        $wheres[] = array('proploc' => $proploc);
    }
    
    if (!empty($propfor)){
        $wheres[] = array('propfor' => $propfor);
    }
     
    $config['where'] = $modx->toJson($wheres);
    ?>


    Search Results Page (id=21)
    <header id="site_header"> Property Search Results </header>
    <div id="content" role="main">
    <h1>[[*longtitle]]</h1>
    [[!bloX? &packagename=`propertylistings` &limit=`0` &classname=`propertylistings` &configs=`propsearch` &tpls=`bloxouter:gcgBloxOuterTpl||row:gcgBloxRowTpl` &debug=`0`]]
    </div> 


    Thanks!

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

      • 4172
      • 5,888 Posts
      Does it generate the correct url to your landing-page?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 30734
        • 44 Posts
        Quote from: Bruno17 at Feb 25, 2014, 11:24 PM
        Does it generate the correct url to your landing-page?

        Thanks for answering Bruno. When I view the page source I get the following:
        <form action="index.php?id=21" method="get" name="search" class="clearfix">


        When I submit the form the site page URL changes to: http://geneseecommercial.com.64-207-187-36.stortzdesigntest.com/index.php?proptype=Office&proploc=Metro+Area&propfor=Lease&searchButton=Search



        Here is a link to the test site. Maybe it will help. http://geneseecommercial.com.64-207-187-36.stortzdesigntest.com/
          • 4172
          • 5,888 Posts
          I think, it should work, as soon, as you switch FURLs on, or try to put a hidden field to your search form:

          <input type="hidden" name="id" value="21" />
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 30734
            • 44 Posts
            Quote from: Bruno17 at Feb 26, 2014, 12:05 AM
            I think, it should work, as soon, as you switch FURLs on, or try to put a hidden field to your search form:

            <input name="id" value="21" type="hidden">

            That worked! however it is not displaying any results. Do you see anything wrong with the php?
              • 30734
              • 44 Posts
              Quote from: Bruno17 at Feb 26, 2014, 12:05 AM
              I think, it should work, as soon, as you switch FURLs on, or try to put a hidden field to your search form:

              <input name="id" value="21" type="hidden">

              Update: I tried using the search code directly from the tutorial at http://www.bdcreative-design.com/blog/data-from-the-migxdb-cmp/

              When I switched it out with my proptype it worked correctly. So that narrows it down to something not being handled properly when searching multiple fields.
                • 4172
                • 5,888 Posts
                set &debug=`1` in your blox-call and we should see the generated sql
                  -------------------------------

                  you can buy me a beer, if you like MIGX

                  http://webcmsolutions.de/migx.html

                  Thanks!
                  • 30734
                  • 44 Posts
                  Quote from: Bruno17 at Feb 26, 2014, 01:46 AM
                  set &debug=`1` in your blox-call and we should see the generated sql

                  Here is the Debug Output

                  Array
                  (
                  [path] => components/blox/
                  [absolutepath] => /var/www/vhosts/geneseecommercial.com/httpdocs/core/components/blox/
                  [packagename] => propertylistings
                  [limit] => 0
                  [classname] => propertylistings
                  [configs] => propsearch
                  [tpls] => bloxouter:gcgBloxOuterTpl||row:gcgBloxRowTpl
                  [debug] => 1
                  [where] => [{"proptype":"Office"},{"proploc":"Metro Area"},{"propfor":"Lease"}]
                  [id] =>
                  [id_] =>
                  [distinct] => distinct
                  [projectname] => blox
                  [resourceclass] => modTable
                  [htmlouter] => div
                  [project] =>
                  [projectparent] => blox
                  [projectpath] => components/blox/projects/blox/modTable/
                  [task] => div
                  [outputSeparator] =>
                  [tplpath] => components/blox/projects/blox/modTable/div/templates/
                  [includespath] => components/blox/projects/blox/modTable/div/includes/
                  [cachepath] => components/blox/cache/
                  [includesfile] => components/blox/projects/blox/modTable/div/includes/getdatas.php
                  [includesclassfile] => components/blox/projects/blox/modTable/div/includes/getdatas.class.php
                  [includesclass] => Blox_modTable_Div
                  [onsavefile] => components/blox/projects/blox/modTable/div/includes/onsavedatas.php
                  [nowtimestamp] => 1393427172
                  [day] => 26
                  [month] => 02
                  [year] => 2014
                  [userID] => 0
                  [totalVar] => total
                  [pageVarKey] => page
                  [perPage] => 10
                  [numLinks] => 5
                  [page] => 1
                  [offset] => 0
                  [queries] => *
                  [selectfields] =>
                  [sortConfig] =>
                  [joins] =>
                  [keyField] => id
                  [parents] => 0
                  [depth] => 10
                  [bloxfolder] =>
                  [documents] => 999999999
                  [IDs] => 999999999
                  [filter] =>
                  [showdeleted] => 0
                  [showunpublished] => 0
                  [debugTime] => 0
                  )

                  Query String:
                  SELECT `propertylistings`.`id`, `propertylistings`.`propname`, `propertylistings`.`propaddress`, `propertylistings`.`propunit`, `propertylistings`.`propcity`, `propertylistings`.`propzip`, `propertylistings`.`proploc`, `propertylistings`.`proptype`, `propertylistings`.`propfor`, `propertylistings`.`propphoto`, `propertylistings`.`propdescription`, `propertylistings`.`propspace`, `propertylistings`.`propprice`, `propertylistings`.`propmap`, `propertylistings`.`propdoc`, `propertylistings`.`contfirstname`, `propertylistings`.`contlastname`, `propertylistings`.`conttelephone`, `propertylistings`.`contemail`, `propertylistings`.`createdon`, `propertylistings`.`createdby`, `propertylistings`.`editedon`, `propertylistings`.`editedby`, `propertylistings`.`deleted`, `propertylistings`.`deletedon`, `propertylistings`.`deletedby`, `propertylistings`.`published`, `propertylistings`.`publishedon`, `propertylistings`.`publishedby` FROM `modx_propertylistings` AS `propertylistings` WHERE ( `propertylistings`.`proptype` = 'Office' AND `propertylistings`.`proploc` = 'Metro Area' AND `propertylistings`.`propfor` = 'Lease' )

                  Query String:
                  SELECT `propertylistings`.`id`, `propertylistings`.`propname`, `propertylistings`.`propaddress`, `propertylistings`.`propunit`, `propertylistings`.`propcity`, `propertylistings`.`propzip`, `propertylistings`.`proploc`, `propertylistings`.`proptype`, `propertylistings`.`propfor`, `propertylistings`.`propphoto`, `propertylistings`.`propdescription`, `propertylistings`.`propspace`, `propertylistings`.`propprice`, `propertylistings`.`propmap`, `propertylistings`.`propdoc`, `propertylistings`.`contfirstname`, `propertylistings`.`contlastname`, `propertylistings`.`conttelephone`, `propertylistings`.`contemail`, `propertylistings`.`createdon`, `propertylistings`.`createdby`, `propertylistings`.`editedon`, `propertylistings`.`editedby`, `propertylistings`.`deleted`, `propertylistings`.`deletedon`, `propertylistings`.`deletedby`, `propertylistings`.`published`, `propertylistings`.`publishedon`, `propertylistings`.`publishedby` FROM `modx_propertylistings` AS `propertylistings` WHERE ( `propertylistings`.`proptype` = 'Office' AND `propertylistings`.`proploc` = 'Metro Area' AND `propertylistings`.`propfor` = 'Lease' )

                  Time to render (row): 1.0013580322266E-5 seconds

                  Time to render all: 0.00484299659729 seconds

                  Total time: 0.017348051071167 seconds
                  • discuss.answer
                    • 4172
                    • 5,888 Posts
                    I see you have multiple proplocs like

                    Metro Area||Jefferson County||Denver||Wheat Ridge


                    is this correct?

                    Than you can try this:

                    if (!empty($proploc)){
                        $wheres[] = array('proploc:LIKE' => '%' . $proploc . '%');
                    }

                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 30734
                      • 44 Posts
                      Quote from: Bruno17 at Feb 26, 2014, 09:47 AM
                      I see you have multiple proplocs like

                      Metro Area||Jefferson County||Denver||Wheat Ridge


                      is this correct?

                      Than you can try this:

                      if (!empty($proploc)){
                          $wheres[] = array('proploc:LIKE' => '%' . $proploc . '%');
                      }


                      It works! Thank you very much for you help! I think i may have to buy you a beer like your signature suggests, hah.