October 3rd, 2015: You can now download code as a plugin.
Stop! There's a better way.
This snippet is available as a plugin with Gravity Perks, a suite of over 46 premium Gravity Forms plugins!
I’ve been using this snippet for quite some time with my Gravity Forms development. I never thought to share it until a client was complaining to me about how much of a hassle it was to test their multi-page registration form with each page chock-full of required fields.
This is exactly why I use this snippet. I work with Gravity Forms all day every day and given Gravity Forms’ continuing popularity, there is a good chance you have found yourself working with this awesome plugin more and more. And the more you work with Gravity Forms, the more you realize how mind-numbingly tedious it is to enter field after field of dummy info so you can submit the form without hitting the required field validation error.
This simple snippet will allow you to “unrequire” all of your form’s required fields by adding a gwunrequire
parameter to your query string. Just like that you can bypass any required field
Using the Snippet
- This will work with even Gravity Forms v1.0 but that’s no excuse not to be running the latest version.
- Already have a license? Download Latest Gravity Forms
- Need a license? Buy Gravity Forms
- Copy and paste the snippet into your theme’s functions.php file.
- You’re good to go! Make sure you are logged in as an administrator and add
gwunrequire
as a query parameter to any URL where you are displaying a Gravity Form to bypass any required fields.
Example:
http://myurl.com/my-form-page/?gwunrequire=1
Example on GF Form Preview
http://myurl.com/?gf_page=preview&id=1&gwunrequire=1
There are some configuration options available. Review the usage instructions below for more details.
Basic Usage
The basic usage requires that the user be logged in as an administrative user and that the gwunrequire
parameter be present in the query string.
new GWUnrequire();
Enable for All Users (including visitors)
Allows you to unrequire fields without being logged in. Not advisable for live servers.
new GWUnrequire( array(
'admins_only' => false
) );
Enable Automatically (no query parameter)
You may find that you don’t want to be bothered with having to add the query parameter. You can disable this requirement to allow administrative users to automatically bypass required fields.
new GWUnrequire( array(
'require_query_param' => false
) );
Parameters
admins_only bool optional
Only allow administrators to bypass required fields. Defaults to
true
.require_query_param integer optional
Require the
gwunrequire
query parameter to be present in the query string to bypass fields. Defaults totrue
.
Summary
You might think it would make more sense to simply wait until you’ve ironed out all the kinks before setting your fields as required. That is viable for small forms, but for larger forms it can be very painful to go back through tens (hopefully not hundreds) of fields to set a single setting.
With this approach, you can configure the field completely the first time through. No need to hassle with the tiresome task of marking each field as required at the end, or worse, forgetting to do so.
If you are debugging new issues that have popped up with old forms, you will be especially appreciative of how much time this snippet can save you. This is the scenario that I have found this snippet to be the most beneficial.
I hope you find this useful and look forward to any feedback you have!
Did this resource help you do something awesome with Gravity Forms?
Then you'll absolutely love Gravity Perks; a suite of 46+ essential add-ons for Gravity Forms with support you can count on.
Hi – Seems like a nice plugin, but not able to make it work. As there are no plugin settings, what exact query string do I need to add at the end of the form URL when logged in as an administrator, is it always “?gwunrequire=1” (without the quotes) or something else depending on the form or page id. I tried the ?gwunrequire=1, but it doesn’t work. Any guidance please.
Hi Ambuj, correct, you need to add the parameter to the URL. If you want this functionality without having to touch code, check out our premium version: https://gravitywiz.com/documentation/gravity-forms-live-preview/