Homepage Cache Prevents External Form from Submitting Properly

Permalink
Hi all,

My team and I have come across an interesting situation with many of the C5 (v5.6.3.2) builds we've been working on recently: it appears that caching on the homepage is interfering with the submission of external forms found on that page. This is only an issue when you are not logged in, which is why we didn't catch it sooner.

I have tried an assortment of cache settings as well as extending the core block controller to manually disable caching on all external forms:

<?php
class ExternalFormBlockController extends Concrete5_Controller_Block_ExternalForm {
   protected $btCacheBlockRecord = FALSE;
   protected $btCacheBlockOutput = FALSE;
   protected $btCacheBlockOutputOnPost = FALSE; 
   protected $btCacheBlockOutputForRegisteredUsers = FALSE;
}

Searching online hasn't provided many clues and the only interim solution that seems to work is disabling cache completely on the homepage (which is unacceptable long-term). I've read that you can disable cache on a per block basis, but not how.

To reproduce:
- Create a new area on homepage
- Add external form
- Try to submit with default cache settings

Any ideas?

ChrisWright
 
WebcentricLtd replied on at Permalink Reply
hi, do you have any more info?

In what way is the cache interfering - what are the symptoms?
ChrisWright replied on at Permalink Reply
ChrisWright
Hi, and thank you for taking the time to respond.

It's an odd situation in that I'm not entirely sure -what- the caching is doing to interfere, just that the issue doesn't arise with caching off. I'll try to explain..

Normally when you submit an external form, the page refreshes and the controller task referenced in your action is triggered for your form, correct? Well for whatever reason, our task isn't being triggered. Everything else appears to be fine. The page refreshes (naturally), and the correct things appear to be happening in the URI (like the tokens and task appearing), but the controller never appears to be hit.
WebcentricLtd replied on at Permalink Reply
the external form functionality seems to work ok in my test system if I just try a sample form out (with or without caching).

What is the action in your form set to?

What does your form actually do - are you uploading any files, doing anything complicated that might involve permissions at all?
ChrisWright replied on at Permalink Reply
ChrisWright
The form isn't doing anything spectacular at all.

Here's the form tag:
<form id="contactForm" action="<?php echo $this->action('send_message')?>" method="post">


And here's the controller:
<?php 
defined('C5_EXECUTE') or die("Access Denied.");
class FooterFormExternalFormBlockController extends BlockController {
   public function action_send_message() {
      // Helpers
      $val = Loader::helper('validation/strings');
      $txt = Loader::helper('text');
      $mail = Loader::helper('mail');
      // Collect user input
      $name = $txt->sanitize($this->post('name'));
      $cookie_jar = $this->post('cookie_jar');
      $fromForm = 'footer contact form';
      if($cookie_jar!=NULL) {
         $this->redirect('/thank-you?fail');
      }


Thanks again for taking the time to try to help.