Jump to content

Template caching and deactivating post and get variables - How to?


Juergen
 Share

Recommended Posts

Hello @ all,

I have a page with a contact form, which is cached. After submitting the form the cache is active.  I use the template cache. There is the possibility to add deactivating cache disabling post and get variables.

So I have included a hidden field in the template:

<input type='hidden' id='aftersub' name='aftersub' value='1'/>

Then I added the hidden field to the post fields of the template cache tab, but the template cache will not be disabled after submission.

I am not a PHP-pro, so can anyone tell me how to use the cache disabling variables correctly?

Thanks in advance

Link to comment
Share on other sites

What exactly is the problem?

If you may do a redirect after form processing, the post var is lost.

Ok, this causes the problem. I use a redirect to the same page after there are no errors to prevent double form submission. After the redirect only the success message will be shown, but this only works if the cache is disabled. In my case I see the (empty) contact form again without the success message, because the page will be reloaded from the cache. This is the problem.

Link to comment
Share on other sites

$session->redirect('./?nocache=1', false);

Add that GET variable in your cache settings.

Alternatively use one time csrf tokens for double submit prevention:

// For your form
$name = $session->CSRF->getgetTokenName('contact');
$value = $session->CSRF->getSingleUseToken('contact');

// On submission, will throw after the first validation
try{
  $session->CSRF->validate('contact');
} catch (WireCSRFException $e) {
  // Double or invalid submit
}
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...