Forums

Issue with form input cache

jebediah 17 Jul, 2009
I have the latest version of ChronoForms & Joomla. I have a problem where if a user types in all their information on their browser, and hits the back or forward button and comes back to the form page they will lose all the data entry they have typed. I have tested this on IE8, firefox 3.5, and latest version of opera and this problem occurs on all of them. I have cache enabled in my global configuration and I still have this issue.

If anyone can give me any suggestions, I would appreciate it.
GreyHead 17 Jul, 2009
Hi jebediah,

That's more or less how browsers work. Not all of them will keep the data if you leave the page (though I seem to recall that FireFox does sometimes). You could add a message suggesting that that stay on the page until they hit the submit button?

If you turn on "Republish fields if error occured" in the Form General Tab then ChronoForms will republish the data when it can - but this may not include leaving the page and returning.

Bob
jebediah 17 Jul, 2009
Thank you for your response. It's odd because usually in other forms, order forms, contact us forms you can hit back and come back and the data is still there. I'll put that verbiage there then warning users their data will get lost😟. Appreciate your assistance.
nml375 18 Jul, 2009
Hi jebediah,
This is somewhat speculative, so don't take my word for it..
That said, the way Joomla and ChronoForms interact, results in http headers being set such as below:
Expires: Mon, 1 Jan 2001 00:00:00 GMT
Last-Modified: Sat, 18 Jul 2009 02:32:12 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache

Expires is post-dated, and the Cache-control contains the must-revalidate keyword.

These pretty much tell Firefox that it cannot re-use a cached copy of this form should the user make use of the history forward/back functions. This then means we actually get a new form rather than the old one, and the old data is lost.

/Fredrik
jebediah 18 Jul, 2009
That makes sense nml375. I know in Joomla Configuration you can enable cache, but in my case that did no good. I wonder if there is a way to alter the settings so it keeps everything in cache. If so, then that would be one huge headache out of the way for a lot of users who utilize chronoforms for their visitors.
nml375 18 Jul, 2009
You could try to overrule these headers using the header() php function, or preferably the JResponse::setHeader() class method. I'd suggest you set the expires-header to roughly "now" + session timeout, and the Cache-Control header to "private" (should tell proxies to behave nicely, yet allow local browser to cache during the session), and remove the Pragma header completely.

/Fredrik
jebediah 22 Jul, 2009
Would this be called header.php? Any idea where I can find it to modify the settings?
nml375 22 Jul, 2009
There would be no need to edit any files; just include something like this at the top of your form code:
<?php
JResponse::allowCache(true); /* Tell Joomla it's ok to cache... */
$session =& JFactory::getSession();

/* But set our own headers to limit the lifetime of the form page */
JResponse::setHeader('Expires', gmDate('r', strtotime('+ ' . $session->getExpire() . ' minutes')), true);
JResponse::setHeader('Cache-Control', 'private', true);
?>


/Fredrik

Edit: Fixed the use of getExpire() as a Class method when it should've been used as an instance-method.
jebediah 23 Jul, 2009
nml375, thank you so much. Your code worked and I personally think this code should be applied to future versions of chronoforms as it would prove very beneficial and convenient.
vanGogh1967 13 Sep, 2010
I try to put this code into my form code.

<?php
JResponse::allowCache(true); /* Tell Joomla it's ok to cache... */

/* But set our own headers to limit the lifetime of the form page */
JResponse::setHeader('Expires', gmDate('r', strtotime('+ ' . JSession::getExpire() . ' minutes')), true);
JResponse::setHeader('Cache-Control', 'private', true);
?>


But when I save the form I get this error message:
Fatal error: Using $this when not in object context in xxx/xxx/libraries/joomla/session/session.php on line 177

What did I wrong or is there need to change something in Joomla-configuration?

Thx
Stephen
GreyHead 13 Sep, 2010
Hi vanGogh1967,

That's a bit odd - I think that usually Joomla! creates the global session. Try adding these line to the beginning of the snippet
<?php
if ( !$mainframe->isSite() ) { return; }  // <-- add this line 
$session = &JSession::getInstance();  // <-- and this line 
JResponse::allowCache(true); /* Tell Joomla it's ok to cache... */

/* But set our own headers to limit the lifetime of the form page */
JResponse::setHeader('Expires', gmDate('r', strtotime('+ '.JSession->getExpire().' minutes')), true);
JResponse::setHeader('Cache-Control', 'private', true);
?>


Bob

Later: corrected JSession::getExpire() - see Fredrik's post after this one
nml375 13 Sep, 2010
Hi Stephen & Bob,
There's indeed a flaw in my previous post, I'll update that as soon as I'm done with this.
The getExpire() method may not be called as a class-method, but only as an instance-method. Thus, the proper call should be $session->getExpire() (in addition to calling the JFactory::getSession() method as described by Bob).

/Fredrik
This topic is locked and no more replies can be posted.