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.
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.
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 39+ essential add-ons for Gravity Forms with support you can count on.
How can I have the form submission redirect to the same page (page that the form was on) after? I have a form on a CPT page that shows a video once the form is submitted.
Hi Christina,
You’ll have to set the confirmation page of the form to the same page. This way when the form is submitted it reloads the page but this time the user would get access to the content.
Best,
Hi there,
Is there any way to configure this to allow for recaptcha to work on the gated form?
Thanks much!
Hi Bryan,
There isn’t any known issue using Recaptcha with this snippet. If you’re experiencing any issues using Recaptcha on the gated form when using the snippet, then you can get in touch with us via our support form, if you have an active Gravity Perks License, so we can dig into this issue.
Best,
Thank you for this plugin! I had some trouble, but eventually got it sorted so I thought I’d leave some feedback in case it helps others.
First, I couldn’t find Custom Fields – it’s in a different spot in the Gutenberg editor (the screen shot shows the classic editor)
I still couldn’t find them and found out that if you have ACF active with Gutenberg, they don’t show. I just ended up creating the fields in ACF, but I found this snippet you can use to restore the default custom fields, if you want https://plugin-planet.com/fix-custom-fields-not-showing-wordpress/
I had an issue where it just showed the confirmation message, but not the page. I realized I needed to set the confirmation to redirect. That might seem obvious, but it’s not in the instructions. I normally just use the confirmation text so it didn’t occur to me right away that I needed to change that.
Hi Jodi,
Thanks for sharing these tips.
Cheers,
Can’t seem to get this to function properly-
Have Page A with a Form on it- form is set to Redirect to Page B, Page B is set to redirect to page A, if a user hasn’t filled out the form already.
Results in an infinite loop- despite filling out the Form- cookies never seem to get set, and so it redirects from Page A to Page B, then page B redirects right back to A.
WP engine site- and WP Rocket is installed- I set settings to never cache the gwsa cookie, and never cache any of the pages involved- but still can’t make it work correctly. Any ideas?
Hi Greg,
I’m guessing this has to do with WP Engine caching. Can you please try the following and see if it helps. Can you get in touch with the WP Engine support and have them exclude Page A and Page B from being cached and see if that helps.
Best,
How do you make it so that they must submit the form every time they access the page meaning when they leave the page and return to the page in the same session or in a new session, they must submit the form again in order to access the page again. I do not want the access regulated by “cookie” since cookie functionality is wonkie depending on device/browser, instead, I would like them to have to submit the form every single time they access the page regardless of session. I have a mobile phone number OTP verification field in the form so that only mobile phone numbers that are in my database can submit the form. Again, how do you make it so that they must submit the form every time they access the page meaning when they leave the page and return to the page in the same session or in a new session, they must submit the form again in order to access the page again?
Hi Ron,
If you set the is_persistent parameter of the configuration to false, site visitors will be required to resubmit the form if they leave the page and return to the page later.
Best,