<![CDATA[ Multipage and FormitRetreiver and &store Issue - My Forums]]> https://forums.modx.com/thread/?thread=100537 <![CDATA[Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-543300
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]]>
boomerang Jul 14, 2016, 01:30 PM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-543300
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562248 From a user perspective the delay (sleep 3) is very annoying.
Is there a trick to make the server respond immediately and do the "sleeping" while preparing the output of the next page (possibly showing some moving gif).

Quote from: BobRay at Oct 11, 2018, 10:50 PM
I'm not sure about your first question, but I don't think there's much chance that a FormIt upgrade will cause trouble for you.
]]>
omegerard Oct 22, 2018, 05:02 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562248
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562045 ]]> BobRay Oct 11, 2018, 10:50 PM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562045 <![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562027
I've got two questions:


  1. Will the problem be solved when I use a more powerful server?
  2. How to make update-proof adaptations in the code?

Regards

Ludo


Quote from: BobRay at Jul 16, 2016, 03: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.
]]>
omegerard Oct 11, 2018, 08:48 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-562027
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-543384
The website is not on the MODX Cloud.

I have not tried the 5 or 10 seconds because of the usability issues. But I can try later when I have access to the files. (Summertime/holiday...)

At the moment I'm running MODX version 2.5 and FormIt version 2.2.10 on PHP Version 5.5.37, CGI/FastCGI running under Redhat. And all cache, varnish, CDN's etc. are disabled.

If you want more information, please let me know.

(I agree with you in that FormIt and FormItRetriever is too complex!)

And many thanks for your effort, not only for this!]]>
Henrik Nielsen Jul 19, 2016, 03:39 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue?page=2#dis-post-543384
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543382
FWIW, the FormIt and FormIt Retriever system seems unnecessarily complex to me. I'd be inclined to use a custom snippet that saved the data in a $_SESSION variable and set placeholders for the form fields, but maybe I'm missing something, and of course that's not an option for a lot of people.]]>
BobRay Jul 18, 2016, 09:52 PM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543382
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543377
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.]]>
Henrik Nielsen Jul 18, 2016, 11:33 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543377
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543369
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.]]>
boomerang Jul 18, 2016, 03:13 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543369
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543365
 $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.)?

]]>
BobRay Jul 18, 2016, 01:03 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543365
<![CDATA[Re: Multipage and FormitRetreiver and &store Issue]]> https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543359 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);
 }
]]>
boomerang Jul 17, 2016, 05:03 AM https://forums.modx.com/thread/100537/multipage-and-formitretreiver-and-store-issue#dis-post-543359