Changing the Cache Time on Your Form Token

Would you like to automatically control how long your form tokens remain valid? With a simple code snippet, you can customize the token expiration time to better suit your needs. This feature is particularly useful for forms that need longer submission windows or enhanced security settings.

This guide will show you how to modify the cache duration for your form tokens.

Understanding Form Tokens

Form tokens are a crucial security feature in WPForms. Each form receives a unique token that:

  • Expires after a set period
  • Prevents spam submissions
  • Blocks direct $_POST requests from spammers
  • Cannot be hard-coded due to their unique nature and finite lifespan

Adding the Code Snippet

To customize your form token cache time, you’ll need to add this code snippet to your site. If you need help adding custom code to your site, please review our guide on adding custom code.

Understanding Token Duration

When modifying token persistence in the code (for example, where we set $times[] = 5 * DAY_IN_SECONDS), keep in mind:

  • This sets a maximum duration of 5 days
  • Tokens may expire earlier if used or invalidated
  • The duration is not guaranteed to be exactly 5 days
  • You can adjust the number of days by changing the multiplier (e.g., change 5 to 7 for a week)

And that’s all you need to change the cache time on form tokens! Next, would you like to learn about enabling GDPR compliance while maintaining phone number detection? Check out our guide on enabling GDPR without IP auto-detection for more details.

Reference Filters