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

    I'm stucked with a formit/getResources problem:

    I would like to have a formit form and a getResource call on the same page.

    After the user fills out the form and hits submit, the page reloads and the input data from the form fields should get passed to a getResources call.

    I tried to place the formit code and getResources call on the same page but it seams, that getResouce doesn't work as expected.

    Do I have to create the getResources call in a formit hook?

    I'm sorry, if this is not very clear but it's a little bit hard to explain because my english is not the best.

    Thank you for your help.




      Modx 2.1.3, PHP 5.2
      • 3749
      • 24,544 Posts
      Yes, if you want getResources to use the FormIt data, I think you'd have to create a postHook for FormIt that gets the information, sets the getResources properties in an array, and sends the information to getResources with $modx->runSnippet('getResources', $arrayName).

      If you know how to use xPDO, and your form and getResources call are not too complex, it might be easier to skip getResources and get and return the resource data directly in your postHook.

      If you want to post an English version of your form and say what you want to do with the results, we might be able to give more specific advice.



      ------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using.
      MODX info for everyone: http://bobsguides.com/modx.html
        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
        • 27117
        • 28 Posts
        Thank you, Bob

        The background is the following: I have 3 parent resources, let's call them TVShowNames (News (id 477), Info (id 558), Sport (id 599). Each parent contains a lot of resources, let's call them TVShows. And each show has a date TV, let's call this OnAirDate.

        What I like to achive is kind of a simple filtering option for displaying the TVShows based on TVShowName and/or OnAirDate.

        I just modified what I have so far and translated it in English. I also removed most HTML Tags for better readability.

        
        /* FormIt */
        
        [[!FormIt?
        	&submitVar=`searchShow_submit`
        	&preHooks=``
        	/* hook reformatFormItDate reformats the Date from dd.mm.yyyy into yyyy-mm-dd */
        	&hooks=`reformatFormItDate,redirect`
            &store=`1`
        	&redirectTo=`540`
        ]]
        
        /* Form */
        
        <form method="post" action="[[~[[*id]]]]" id="searchShow_form">
            <select name="searchShow_list">
        	   <option value="477,558,599" [[!+fi.searchShow_list:FormItIsSelected=`477,558,599`]] >All Shows</option>
        	   <option value="477" [[!+fi.searchShow_list:FormItIsSelected=`477`]] >News</option>
        	   <option value="558" [[!+fi.searchShow_list:FormItIsSelected=`558`]] >Info</option>
               <option value="599"[[!+fi.searchShow_list:FormItIsSelected=`599`]] >Sport</option>
        	</select>
        	<!-- Datum von -->
        	<input type="text" value="[[+fi.searchShow_Date]]" name="searchShow_Date" id="searchShow_Date" class="date-pick" /> 
        	<input type="submit" name="searchShow_submit" class="submit-button" value="Search" />
        </form>
        
        /* FormItRetriever for storing the submitted values */
        [[!FormItRetriever]]
        
        /* getPage/getResources part */
        
        [[!getPage@TBPaging?
            &elementClass=`modSnippet`
            &element=`getResources`			
            &parents=`[[!If? &subject=`[[+fi.searchShow_list]]` &operator=`isempty` &then=`477,558,599` &else=`[[+fi.searchShow_list]]` ]]`
            &depth=`4`
            &limit=`10`
            &pageVarKey=`page`
            &pageLimit=`3`
            &includeContent=`0`
            &includeTVs=`1`
            &processTVs=`1`
            &tvPrefix=``
            &tvFilters=`OnAirDate==[[+fi.searchShow_Date]] 18:00:00`
            &sortby=`pagetitle`
            &sortdir=`DESC`
            &tpl=`SendOverviewWebTV`
        ]]
        
        <div class="pagination">
        <span class="pagination">Page [[+page]] from [[+pageCount]]</span>
        [[!+page.nav]]
        </div>
        
        
        


        Basically, this is working BUT when loading the page for the first time, no results are shown and it takes quite a long time to load.

        Any help is very much appreciated.

        BTW, I'm using Modx 2.1.3, getResrouces 1.5.0 and FormIt 1.5.5
          Modx 2.1.3, PHP 5.2
          • 3749
          • 24,544 Posts
          That's a fairly complex operation so it's going to take time unless you do a lot of custom work (e.g. putting the show data in a set of custom DB tables).

          You could move the getResources call to a postHook, but I'm not sure it would help you with the page-load speed.

          Have you tried &processTVs=`0`? If you can use the raw value of the TV, it will save you a little time.


          This is kind of a wacky idea, but if you could use one of the Resource data fields (e.g., publishedon or createdon) for the OnAirDate rather than a TV, I think it might speed things up considerably.

          If you set the +fi.searchShow_list placeholder in your pre-hook (only if it's not already set), you might get results on the first page load:

          if (empty($modx->getPlaceholder('fi.searchShow_list'))) {
              $modx->setPlaceholder('fi.searchShow_list','477,558,599'); 
          }



          ------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using.
          MODX info for everyone: http://bobsguides.com/modx.html
            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
            • 27117
            • 28 Posts
            Thank you Bob, I will try that out.

            Beside that problem, I ran into another one.

            In my form select values, I have an output modifier to handle the Selects as described in the Formit Tutorial in the offical Add-On Documentation.

            This works well for the 3 single values in my code:

            <option value="477" [[!+fi.searchShow_list:FormItIsSelected=`477`]] >News</option>
            <option value="558" [[!+fi.searchShow_list:FormItIsSelected=`558`]] >Info</option>
            <option value="599"[[!+fi.searchShow_list:FormItIsSelected=`599`]] >Sport</option>
            


            But not for the first value:

            <option value="477,558,599" [[!+fi.searchShow_list:FormItIsSelected=`477,558,599`]] >All Shows</option>
            


            Everytime when I send the form and the page reloads, the last value (599 -> Sport) is selected instead of 477,558,599 -> All Shows.

            Is it a problem of the values which are separated by a coma?

              Modx 2.1.3, PHP 5.2
              • 3749
              • 24,544 Posts
              You might have to change the value of that option to "All" and modify your code. FormIt is probably using in_array() or strstr() and the duplicate values may be confusing it.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html
                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