Speed Up Your Gravity Forms Testing: Unrequire Required Fields
Filling out field after required field can rot your brain. Save a huge amount of time by automatically unrequiring required fields.
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!
Comments
Comments are closed.
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/
Hi David!
We’ve used this snippet on a number of sites (thanks again!). I have a case now where it would be helpful to unrequire automatically for any editor-level user (as well as admins). I think the change would come at line 33 (although line 43 may also need to be changed?), but not sure exactly what it would be. Any help you could share would be appreciated!
Hi Bet, you’d just need to update the “activate_plugins” on this line to a capability that highest capability that your editors have.
current_user_can( 'activate_plugins' )
this is excellent, thanks so much for more great work!
Happy to help! Make sure to check out Gravity Forms Live Preview which includes a UI for this feature and many other tools for speeding up Gravity Forms dev.
Huge timesaver – just what I needed. Thanks!
Glad to help, Clay! If you’re a Gravity Perks users, definitely check out Gravity Forms Live Preview. It is a power-house plugin for testing/debugging with Gravity Forms and it includes a super simple UI for toggling the unrequire functionality on and off. :)
Installed the Plugin. Where is the settings for the Plugin found?
Hi Majeem, this plugin does not have any settings. You would manually activate it by adding the parameter to the query string. If you’re looking for a better implementation of this feature, see Gravity Forms Live Preview.
This is such a useful snippet. It would be be great to expand it to also unrequire other field stipulations within the form. For example, navigation is still restricted when one has not confirmed an email address or has not met the required number of checkboxes defined by GP Limit Checkboxes. An idea for future implementation. Thank you, again!
Definitely a good idea. We’re integrating this snippet with GP Live Preview to make it easier to use (and install). In the future, I could definitely see the value of removing other form restrictions like this.
I think this is pretty brilliant!!!! I’ve been looking for a way to save form data to the database without needing to fill in all the required fields. I was hoping to use this solution tied to a “save” button. Does anyone know if there’s a way to tie this to a submit button. I’m currently using the “Gravity Forms Sticky List” plugin to save retrievable data from a front-end form. The only issue with the “Gravity Forms Sticky List” plugin is that it only has a submit button, when it should really include two buttons, a “Save” and a “Submit”. Thanks in advance for any help!!!
Hi,
I wasn’t able to download the plugin from your webpage. Nothing seemed to happened. I’ve turned off all my adblockers/popup blockers with no avail.
Thanks.
Fixed. Try now, Sam.
Hi David!
I’ve used this snippet successfully for months, but when I tried it tonight, it doesn’t seem to be working. I know WP updated to 4.0, and GF had updates too. Do you know if one of those updates might now make this snippet not work?
I tried making this a plugin, as I prefer not to modify my theme’s functions.php, plus it can be turned on and off more easily. But I’m getting a white screen on activation. Is this working with the latest versions of WP and GF?
Hi Tevya, I added a plugin header. Save this as a file and drop it in your WordPress plugins folder.
https://gist.github.com/spivurno/8748689
[…] my search for the “require all fields” solution, I stumbled across this helpful post that’s perfect for when you’re testing a website with forms and don’t want to […]
[…] my search for the “require all fields” solution, I stumbled across this helpful post that’s perfect for when you’re testing a website with forms and don’t want to […]
Hi.
Great tutorial. With the same logic how would you consider the best way to make a a custom input field required? I do not see the checkbox on admin.
When you say a custom input do you mean a custom field type that you are creating via GF hooks?
Hi David,
Thanks for your answer. Yes it’s my case. A custom field type created by a plugin but I need to make it mandatory.
If you take a look at this article it demonstrates the full process for adding a custom field. If you look at the Add the Form Editor JS section specifically, you’ll see where the
fieldSettings
global variable is updated to include which settings are shown for the custom field type. The field setting you’ll want to add to the list for the required rule is the “.rules_setting”.Great ! I made this appear in admin but now the form does not validate even if the field is fulfilled. I do not understand at all ! Any idea?
Hi Elyssia, wish I could provide more assistance with this but I have limited available for free support. This is something GF Support could probably help you. Good luck!
Hi, It sure seems to be quite straight forward, but for some reason it’s not working for me.
Hi John, thanks for letting me know via email that you got this resolved. :)
Excelling Boss. It helps much. I’ve more than 6 pages & 200+ required (*) fields in my form. I applied this method. its really helpful. keep continue with more.
Glad you found this useful. I know I do!
Where do I put this snippet exactly?
In your theme’s functions.php file.
Thanks David! I too have an 11 page form that needs to be developed so this is going to be a big timesaver. Thanks for sharing this.
My pleasure! And glad to hear it’ll save you some time.
Very cool! I will definitely be using this– have several client forms with 100+fields (long camp registration forms)
Awesome dude! Thanks… lifesaver :)
Welp… this is another snippet that is going to be a huge time saver! It will especially help with our 6 page employment applications. All of your snippets are great and work so well you would think they would be included features in GF.
Genius! One of my customers has a 12 page form with multiple conditionals that all need testing, it’s been driving me nuts.
That’s a great use case! Thanks for sharing.