We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I've got a a 3 page form which has the following calls

    Step (Page 1)

     [[!FormIt?
       &hooks=`redirect`
        &validate=`donation_type:required, amount:required`
           &store=`1`
           &storeTime=`1200`
       &redirectTo=`2`
    ]]  


    Step 2 (Page 2)
    [[!FormItRetriever]]
     [[!FormIt? &submitVar=`regular-donation` &hooks=`redirect` &store=`1` &validate=`nospam:blank,email:email:required,DonorTitle:required,Donor_FirstName:required,Donor_LastName:required` &redirectTo=`4` ]]
    


    To this stage all works well the information from Page 1 has been stored and appears in the hidden fields of Page 2

    Step 3 (Page 3)
    [[!FormItRetriever]]
     [[!FormIt? &submitVar=`dd_donation` &hooks=`email,redirect` &validate=`nospam:blank,email:email:required,DonorTitle:required,Donor_FirstName:required,Donor_LastName:required,Donation_Frequency:required` &emailTpl=`regular_donation_emailTpl` &emailTo=`[email protected]`  &redirectTo=`5` ]]
    


    However the fields from Page 2 do not appear, the fields from Page 1 do... The form does not submit because the fields that should appear from Page 2 are not there and these are required fields.

    Suggestions please as to why the &store=`1` doesn't appear to be storing the data from Step 2 to Step 3.

    Thank you

    Environment:

    MODX Cloud
    Revo 2.5.0
    Formit 2.2.10

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

    [ed. note: boomerang last edited this post 7 years, 9 months ago.]
      Helen Warner
      Number one pixel!
      Proud to be linked with MODX at Crimson Pixel
      • Helen Warner
        Number one pixel!
        Proud to be linked with MODX at Crimson Pixel
      • Couple things to check:

        1. What do you see in the cache file for that formit submission? It should be in the folder:
        {$context+key}/elements/formit/submission/{$md5_hash}


        Check it after the 1st step and again after the 2nd step. Let me know what happens: if it gets deleted, or if the values in it become invalid somehow, etc. Maybe you can post the cache files here or in slack.

        2. Between lines 42 and 43 of the FormItRetriever snippet, you could dump the
        $data
        variable and see what's in there at that point. You should be able to step through the form and see that variable's value. Does it have the value you're expecting?
          [sepiariver.com] (https://sepiariver.com/)
        • Are you referring to the cache/includes/elements? Otherwise I'm not sure where I'm looking. The information from page 2 to page 3 does appear if you refresh the page, so it seems to be stored but doesn't appear immediately.

          UPDATE: Looked via FTP and found the submissions folder.... it appears that all the fields are being passed, but will run form and check each stage and get back to you. [ed. note: boomerang last edited this post 7 years, 9 months ago.]
            Helen Warner
            Number one pixel!
            Proud to be linked with MODX at Crimson Pixel
          • I've gone through submitting the form and checked the cache. The data expected appears in the first stage in the cache and this appears in the hidden fields.

            The data also appears in the cache at the next stage but does not appear in the hidden fields UNTIL you refresh the page....
              Helen Warner
              Number one pixel!
              Proud to be linked with MODX at Crimson Pixel
            • discuss.answer
              • 3749
              • 24,544 Posts
              You could try this to see if it's a timing problem. The cache file may not be written fast enough to be there when FormIt retriever tries to get it (though that seems unlikely).

              In the file: core\components\formit\model\formit\fidictionary.class.php

              around line 138, find this code:

               public function retrieve() {
                      $cacheKey = $this->formit->getStoreKey();
                      return $this->modx->cacheManager->get($cacheKey);
               }
              

              Change it to:

               public function retrieve() {
                      sleep(3);  /* add this line */
                      $cacheKey = $this->formit->getStoreKey();
                      $modx->log(modX::LOG_LEVEL_ERROR, 'FormIt CacheKey: ' . $cacheKey); /* And this line */
                      return $this->modx->cacheManager->get($cacheKey);
               }
              


              The second added line is so you can look in the Error Log and see if the key stays the same (it should).

              If that solves it, try sleep(1). If it doesn't solve the problem, remove the extra lines. If it does, just remove the error log line. [ed. note: BobRay last edited this post 7 years, 9 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
              • Quote from: BobRay at Jul 16, 2016, 08:43 PM
                You could try this to see if it's a timing problem. The cache file may not be written fast enough to be there when FormIt retriever tries to get it (though that seems unlikely).

                In the file: core\components\formit\model\formit\fidictionary.class.php

                around line 138, find this code:

                 public function retrieve() {
                        $cacheKey = $this->formit->getStoreKey();
                        return $this->modx->cacheManager->get($cacheKey);
                 }
                

                Change it to:

                 public function retrieve() {
                        sleep(3);  /* add this line */
                        $cacheKey = $this->formit->getStoreKey();
                        $modx->log(modX::LOG_LEVEL_ERROR, 'FormIt CacheKey: ' . $cacheKey); /* And this line */
                        return $this->modx->cacheManager->get($cacheKey);
                 }
                


                The second added line is so you can look in the Error Log and see if the key stays the same (it should).

                If that solves it, try sleep(1). If it doesn't solve the problem, remove the extra lines. If it does, just remove the error log line.

                Thanks for the response Bob, I tried just the code Sleep(3) and that worked - Sleep(1) didn't. I then realised there was an additional line of code to add to check the error log but that caused the form to fail so I removed it. I did check the error log and there was nothing in it.

                So I just amended to:

                public function retrieve() {
                        sleep(3);  /* add this line */
                        $cacheKey = $this->formit->getStoreKey();
                        return $this->modx->cacheManager->get($cacheKey);
                 }
                  Helen Warner
                  Number one pixel!
                  Proud to be linked with MODX at Crimson Pixel
                  • 3749
                  • 24,544 Posts
                  Sorry, the line should have been:

                   $this->modx->log(modX::LOG_LEVEL_ERROR, 'FormIt CacheKey: ' . $cacheKey); /* And this line */


                  It's unnecessary now, though, since sleep(3) fixed it. The code would never work if the $cacheKey were wrong.

                  I'm surprised, though, that sleep(1) doesn't work. You might try sleep(2), or even usleep(1500).

                  I assumed that the cache file had not been written yet when the retriever tries to read it. I didn't see how that could be possible, since the retrieval action is in a whole new request. There should be plenty of time between the write and the read.

                  Looking at the code, I found that CacheManager locks the file with flock while writing to it and implements a 1-second delay before retrying if it can't obtain the lock. Maybe the cache file is not unlocked in time for the retrieval. Maybe the cache file is also being updated (and locked again) at some other point during the process.

                  I couldn't find the relevant get() function to see how it handles locked files and whether it has a built-in delay and retry.

                  From my reading, file locking is a black art that almost no one understands completely.

                  What kind of server is it, and are you using any auxiliary cache (APC, memcached, etc.)?

                    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
                  • Hi Bob, tried sleep(1), sleep(2) and usleep(1500) - none of these worked, the only one that works is sleep(3)... and have to confess you lost me at:

                    Looking at the code, I found that CacheManager locks the file with flock while writing to it and implements a 1-second delay before retrying if it can't obtain the lock. Maybe the cache file is not unlocked in time for the retrieval. Maybe the cache file is also being updated (and locked again) at some other point during the process.

                    I couldn't find the relevant get() function to see how it handles locked files and whether it has a built-in delay and retry.

                    From my reading, file locking is a black art that almost no one understands completely.

                    :)

                    With regard to server, this has been set up as development space on MODX Cloud and I'm currently not implementing any other specific caching.
                      Helen Warner
                      Number one pixel!
                      Proud to be linked with MODX at Crimson Pixel
                      • 12028
                      • 152 Posts
                      Hi Helen,

                      Same deal here, I've tried my backup (See: https://forums.modx.com/thread/100242/multistep-form-with-empty-fields-until-refresh-of-page#dis-post-543304) under PHP version 5.5, 5.6 and 7 with Bob's sugestions and still without any luck. All cache management are disabled.
                        - A small step for mankind, so why not take two...

                        Working with web production, graphic design/workflow, photo and education - but are trying to get a life in between!