January 12, 2023: Added
cookie_expiration
parameter to allow configuring when the cookie that tracks submitted forms expires.November 23, 2021: Added
gfsa_has_access
filter for filtering whether the current viewer has access to a given post.March 2, 2021: Updated snippet to run as a Singleton plugin. Added
gw_submit_to_access()->has_submitted_form()
helper method.June 21, 2017: Improved support for automatically showing required form if no required message is specified.
March 2, 2017: Updated submitted forms cookie to be persistent by default. Added new "is_persistent" option to disable this.
March 1, 2017: Added support for "gwsa_requires_submission_redirect" option to allow automatically redirecting to a specific page if the user requires access.
March 23, 2016: Added support for requiring a form to be submitted before any page can be accessed. Added support for storing submitted forms in user meta.
March 3, 2015: Added support for shortcodes in "gwsa_requires_submission_message" custom field. Fixed issue where json_decode() did not return an array.
You have a post or page you’d like to protect but you don’t want to require the user to sign up for a user account and you just don’t need a full-blown membership system. All you want to do is collect a few details about the user for your mailing list or CRM.
This plugin provides an easy way to accomplish this. Any post-based content (that includes pages and custom post types) that support custom fields can be locked down. You set a few special custom fields and the Gravity Forms Submit to Access plugin takes care of the rest.
Getting Started
Check requirements
- Make sure you have Gravity Forms installed and activated.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
Install the plugin
- Click the “Download Code” button above and save the file to your Desktop.
- Drop the file into your WordPress plugins folder via FTP – or – zip the file up and upload it via WordPress plugin uploader.
Configure the plugin
- Read on for step-by-step instructions
Locking Down a Page
Navigate to the Edit screen for any post, page, or any custom post type.
Enable “Custom Fields via the Screen Options at the top of the page. There is a good chance they are already enabled.
Add a custom field named gwsa_require_submission with a value of
1
.Add a custom field named gwsa_form_ids and set the value to the ID of whichever form the user should submit to gain access to this page.
That’s it!
Custom Field Options
gwsa_require_submission (string) (required)
Add this custom field with a value of
1
to require a Gravity Form to be submitted to gain access. Set this value toper_page
to require the submission on the page itself.gwsa_form_ids (bool) (optional)
Add this custom field and set the value to the ID of the form which must be submitted to gain access to this page. If there are multiple forms that can be submitted to gain access, you may include them as a comma-delimited list (i.e.
1,2,3
). If any form can be submitted to gain access to this page, do not add this custom field option.gwsa_requires_submission_message (string) (optional)
Override the default message that is displayed when the user does not have access to view the content of this page.
Use the
{form}
custom merge tag to control where the required form is output alongside the requires submission message. This allows you to wrap the form and message in your own custom markup.gwsa_requires_submission_redirect (string) (optional)
Provide a URL to which the user will be redirected if they do not have access to view the content of this page.
Per Page Locking
By default, any pages locked by the same form submission will all be unlocked simultaneously. For example, let’s say you lock down two pages on your site, called Welcome New Members and House Rules, and you only want members of your site to be able to view those pages. You can use the same form to unlock both pages by inserting the same Form ID into the gwsa_form_ids field on both pages. When a user submits the form on either of the two pages, both pages are unlocked at the same time.
In some cases, you only want to unlock a page when a form is submitted on that page. In the case of the examples pages above, you might have a simple Terms of Service form that requires the user check a box indicating they have read the terms before they can view the content. If you set the gwsa_require_submission custom field value to per_page
instead of 1
, the page content is only unlocked when the user submits the form on that specific page.
Global Parameters
requires_submission_message (string) (optional)
Define the default message that is displayed if the user does not have access to the content. This value will be overridden if a post-specific message is set via the gwsa_requires_submission_message custom field option. Defaults to
'Oops! You do not have access to this page.'
.bypass_cache (bool) (optional)
Enabling this option will allow the script to bypass any page/cookie caching by fetching the post content via AJAX. Defaults to
false
.loading_message (array) (optional)
If bypass_cache is enabled, this option allows you to control the loading message which is visible while the post content is being fetched via AJAX.
is_persistent (bool) (optional)
The cookie that stores which forms have been submitted for the visitor is persistent by default. Set this to
false
to make the cookie session-based.enable_user_meta (bool) (optional)
Set this to
true
to save submitted forms in the user meta rather than a cookie. Only works for logged-in users.cookie_expiration (bool) (optional)
Set this to a timestamp (in the future) at which the cookie should expire. For example, to have the cookie expire each night at midnight, set the value to:
strtotime( 'midnight tomorrow' )
.
Any questions?
This is a bare bones plugin. It uses WordPress’ custom fields UI to handle setting the options and advanced configuration should happen in the plugin.
If this proves to be a popular resource, I’ll be happy to enhance it to be even easier to use.
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 47+ essential add-ons for Gravity Forms with support you can count on.
Shoot – doesn’t work with Divi Page Builder.
Hi Melissa,
This snippet should work with Divi page Builder. We’ve tested it locally and had great results.
If you’re Gravity Perks subscriber, drop us a line in support and we’ll be happy to dig into this for you.
The gwsa_requires_submission_message override doesnt work.
Please be thorough before you post and wast people’s time. Thanks
gwsa_requires_submission_message DOES NOT WORK
Hi Derrick,
It’s unfortunate it didn’t work for you. I just tested the code snippet and can confirm it works. We’ll be happy to assist you to get it working if you get in touch with us via our Support Form.
Best,
I have implemented this based on the instructions. The correct form shows in the page to gate the content, but the page content doesn’t display after submitting the form. I have it implemented on these two pages: https://diamondassets.com/top-6-tips-to-gain-the-best-financial-roi-on-your-technology-upgrade/ https://diamondassets.com/the-ideal-time-to-purchase-new-technology-and-how-to-budget-for-it/
Hi Aaron,
When testing locally it seems to work as expected. If you have an active Gravity Perks License, you can get in touch with us via our support form and we’ll be happy to dig into this further.
Best,
We’re experiencing a bug with the plugin in Safari, Chrome, Opera and Firefox on Mac. For some reason the bug does not manifest in Brave.
When the user submits the form, instead of being taken directly to the content page, the form is just blanked out. When the user clicks submit again, they are taken to the page.
Any idea what can be causing this?
Hi Bill,
I’ll suggest you run a Theme/plugin conflict test to check if another plugin or code is causing this. Also, you can try using our Cache buster plugin in case this is a caching-related issue. If this doesn’t help, then you can get in touch with us via our support form, if you have an active Gravity Perks license, so we can assist you further.
Best,
Hi,
The plugin is working great – but only seems to hide the_content() – I also use ACF to display a link to a PDF and an image that links through to a pdf. Both of these are displaying next to the form. Can the form be configured to display on it’s own page, or alternatively is there a way to hide the output of ACF fields as well as the_content()?
Thanks!
Hi Nick,
This will require some customization of the snippet. If you have an active Gravity Perks license, you can send us a message via our support so we can take a closer look at your use case.
Cheers,
We are running into the same issues with a submission causing the user to return to the initial page and not the thank you page.
Are there any suggested fixes, I see in the comments others have ran into this but doesn’t seem to be any clear fix (apologies if I’m missing it).
Thanks in advance for any help!
Hi Bryan,
Historically these issues are related to the cache.
If you have an active Gravity Perks License, you can get in touch with us via our support form so can dig into this.
Best,
This works great for me in Chrome, but in some other browsers (Firefox for example) I am consistently redirected back to the page with the Gravity Form. My guess is the cookie isn’t being properly stored, so the form sends the user to the appropriate page of content via GF confirmation redirect, but then the gated content sends the user back to the page where the form is hosted because it can’t find the cookie.
It occurs to me that this would always be the case for the increasing number of people who block cookies.
Is there a way to exempt the cookie redirect from the page with the gated content, when the user arrives via the GF confirmation redirect?
Obviously this would mean users blocking cookies will always have to fill out the form, but it’s better than a redirect loop.
Thanks!
Hi Ben,
When testing on Firefox it seems to work as well, it should work on any browser but as you mention it relies on the store cookie. If you have an active Gravity Perks License, you can get in touch with us via our support form so can dig into this.
Cheers,
I have used this plugin with a simple 1-question gravity form (email, required field). But my client now wants to ask more questions, and some questions only appear based on other question’s answers (conditionals). When using this new gravity form, the form does not want to display on the page (the wrapper of the form style is set to display:none on page load, and when manually overwriting it to display:block, all of the questions appear–meaning the display conditionals are not working– but the conditional logic behind submitting the form is there.
When setting the page to password-protected, the form loads and works fine (conditionals work). Once the page is set to normal (published), no password, it has the errors. I have also tried using this on a blank page and with my theme builder (Divi).
I have played with the bypass_cache to see if it was an ajax thing, but that didn’t make any difference.
Any idea whats going on here or how I can make the form work properly on a regular published page?
Hi Vicky,
I can’t confirm why it is not working, it could be related to Conditional Logic or with how the form is embedded with Divi. If you have a Gravity Perks License, you can get in touch with us via our support form so we can take your request and forward it to our developers to see if this can be supported.
Hello folks, It is possible to show my sidebar after completed the form? if yes, how? Thank you folks.
If I understand correctly, you want to lock down the entire page including the sidebar. The best way to lock down the page content including the sidebar is to redirect to another page when a locked page is accessed. To do this, set the “gwsa_requires_submission_redirect” custom field on your restricted page and set the value to the page the user should be redirected to gain access to the restricted page.
I hope this helps.
Best,
Hello folks, I wanted to hide/show my sidebar content accordingly if the form completed. It is possible to hide first my sidebar content and after the form completed it will show? Note: Not the entire page/post will restrict, only the sidebar content I want to be restrict.
Thank you folks.
We don’t have a ready method for this. The simplest path forward would be to add a custom wrapper to your sidebar like so:
if ( gw_submit_to_access()->has_access( $post_id ) ) { // Your sidebar! }
After the form is submitted, refresh the page and the sidebar should appear.
Thank you for this plugin! I am having a minor issue. I am asking for just an email with my gravity form. When the form is displayed, that field (email) is not using autofill/suggestions (when you click the email input box, it does not give any suggestions of emails you have used on other forms). Any idea on how to get this feature?
Hi Vicky,
Can you replicate this behavior across browsers? Locally it seems to be working as expected.
If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.
Cheers,
Hi, I have tried Gravity Forms Submit to Access But its not working. after setting up post type.
I am using this with learndash courses. My main purpose is to ask user to submit gravity form and then access the course
Thanks
Hi Inzaman,
When testing locally, it seems to work as expected. It should work on Post, Pages, and Custom Post Types.
If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.
Best,
Thank you for your reply unfortunatly my license is support expired i thought it could help.
I deactivate all other plugins and just runing gravity forms Gravity Forms Submit to Access Leandash
I am using Siteground hosting
Thank you
I just test it working with post and pages issue only with learndash its not working with that.. thanks
Hi Inzamam,
Thanks for the heads up.
If Learndash is using WordPress Custom Post Types, the snippet should work as well. Historically, issues with this snippet are related to the cache.
Cheers,
Hi!
Does the code no longer need to be edited and the .zip uploaded as a its own plugin? Confused by the copy stating to download code but button says download plugin..
TIA
Hi,
The code can be edited and zipped and installed as a plugin or you can copy and paste the code into your function.php file or a Code snippet plugin.
Best
Had this working on some private pages for testing – a landing page with a form that redirects to the gated post. The gated post has gwsa_form_ids set to the GF form, gwsa_require_submission set to 1, and gwsa_requires_submission_redirect set to the landing page with the form. This afternoon the client made the pages public and reported that the gated page was redirecting back to the form page. I double-checked the settings based on the instructions above, and set up on a local instance with all settings identical, and it worked as expected.
On the live site, using Firefox, if I have been logged in to wordpress (and have session cookies set), the process works, but if I’m in a private window it does not.
On the local site, it works whether there are session cookies or not (i.e., even in a private window).
Hi Michael,
Thanks for reaching out. It should work on a private window as well.
If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.
Best,
Hi Dario,
Thanks for the reply. Before I approach the client regarding escalating support, are you aware of any conflicts this might have with WPEngine?
Hi Michael,
From what I understand, the snippet should work with WP Engine and most hosting providers.
If you encounter any setbacks let us know and we will try to help!
Best,
Can this be used to protect only a part of a page? ie. If I have a full page with lots of details but I only want to protect the download links on my page with a form?
Hi Morten,
This snippet currently only works to protect the entire Post or Page.
If you have an active Gravity Perks License, you can get in touch with us via our support form with your account email address and we’ll be happy to dig into this further.
Best,
Great plugin but with Gravity Forms version 2.5.6 I now get a blank white screen when I click on the page in WP admin. The frontend works fine, it’s only in admin and only on the pages that are using the Custom Fields for this plugin and the latest version of Gravity Forms.
No problems prior to the GF upgrade.
Hi Rocio,
I’m having trouble reproducing this issue locally, it seems to be working. Could you try updating to the latest GF version which is 2.5.7. If you have an active Gravity Perks License, can you open a ticket with us via our support form, with your account email so that our developers can take a look into it.
Best,
Hi Dario, Thank you for the quick response. I realize that the issue was that the cookie was not set. Once the cookie was set the “blank/white” screen for my locked pages in WP admin showed up just fine. Not a real issue, and great little plugin.
Thanks again! R
I’ve used this before with a form on a separate page, but I’m trying to use it for multiple pages that load a specified form in place.
The problem is once submitted, the Gravity Forms confirmation message is displayed, but it does not then load the page content. One must reload the page.
Is there a way to just have it display the page content on the form submission without showing the confirmation message at all?
I thought that’s what setting a custom field of ‘bypass_cache’ with a value of ‘true’ would do, but it does not seem to.
I must be missing something. Please advise.
Actually, I changed the confirmation to type Redirect of {embed_url}, and that seems to do the trick. Is that the correct way?
Is the ‘bypass_cache’ with a value of ‘true’ still needed? Not clear how that works or why it’s needed.
Hi Michael,
Enabling bypass_cache option will allow the script to bypass any page/cookie caching by fetching the post content via AJAX. Setting the bypass_cache will load the contents via AJAX without a page reload. If bypass_cache is enabled, the loading_message parameter allows you to control the loading message which is visible while the post content is being fetched via AJAX.
If you are a Gravity Perks customer, drop us a line and we’ll be happy to dig into this to see if this is possible.
Thanks for the tip about redirect to {embed_url}. I was having the same issue.
Hi guys, I’m having a problem getting this to work using Beaver Builder, the fields are created using ACF (basic text fields), I just never get the form before the content. Going on other comments this appears to be working fine with DIVI or Elementor so wondering if anyone has got this to work with Beaver Builder or anything I may be missing, any advice much appreciated. I also have no caching enabled at the moment as the site is in dev.
Hi MicKe,
I’m not really sure why it isn’t working, but instead of using ACF to create the custom fields, could you use the WordPress Custom Fields instead and see if that works.
Best,
Hi! Thanks for providing the plugin!
I have set up the custom fields on my custom post type after form submission it will just redirect to the restriction message so they still can’t access the protected content.
Hi Carl,
If you already have custom fields parameters set up correctly as described in the tutorial above, try clearing the cache and see if that resolves the issue. You could also run a theme/plugin conflict test to check if another plugin is causing this issue.
In case this doesn’t work for you, then we may have to log in to your site to check the setup and troubleshoot the issue there. So if you have a Gravity Perks license, you can reach us via our support form so we dig into this.
Best,
Do you have any videos? I did everything that is written here but still, nothing works
Hi! Thanks for providing the plugin!!!
Are there any known compatibility issues with Elementor Website Builder?
Once I add the custom fields, save the page, I can’t edit the page (or the fields) anymore. I also get this error “The editor has encountered an unexpected error.”
Thanks for your help,
Ken
Hi Kenneth,
The snippet shouldn’t cause any issue with Elementor. It could be with the way you’re creating the custom fields. You may want to check out this article on how to add custom fields in Elementor. If you have a Gravity Perks License and you’re still having issues, you can send us a message via our support form so that we can dig into this.
Best,
This is the same behavior I see when working with Divi Page Builder. The issue is you haven’t submitted the form and set a cookie in your browser giving you access to the page you are trying to edit. Just go submit your access form to set a cookie then return to edit your locked content page. The problem lies in that Elementor (as well as Divi) is loading the full page and not just the WordPress text editor thus getting blocked by the submit to access perk.