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!

View Plugin Buy Gravity Perks

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

  1. Using the Snippet
    1. Basic Usage
    2. Enable for All Users (including visitors)
    3. Enable Automatically (no query parameter)
  2. Parameters
  3. Summary

Using the Snippet

  1. This will work with even Gravity Forms v1.0 but that’s no excuse not to be running the latest version.
  2. Copy and paste the snippet into your theme’s functions.php file.
  3. 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 to true.

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

  1. Ambuj
    Ambuj September 3, 2018 at 11:04 am

    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.

  2. Bet Hannon
    Bet Hannon September 13, 2017 at 4:30 pm

    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!

    1. David Smith
      David Smith Staff September 13, 2017 at 9:56 pm

      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' )

    1. David Smith
      David Smith Staff April 2, 2017 at 6:13 pm

      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. :)

  3. UaMV
    UaMV May 26, 2016 at 10:31 am

    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!

    1. David Smith
      David Smith Staff June 20, 2016 at 10:20 pm

      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.

  4. David Tan
    David Tan March 25, 2016 at 5:36 pm

    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!!!

  5. Sam
    Sam November 1, 2015 at 10:08 pm

    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.

  6. Bet Hannon
    Bet Hannon October 23, 2014 at 11:50 pm

    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?

  7. Tevya
    Tevya October 22, 2014 at 11:35 pm

    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?

  8. Gravity Forms – Automatically Set All Fields to Required - Andrew Good August 21, 2014 at 6:22 am

    […] 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 […]

  9. Gravity Forms - Automatically Set Fields to Required August 18, 2014 at 4:50 pm

    […] 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 […]

  10. Elyssia
    Elyssia June 12, 2014 at 10:10 am

    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.

    1. David Smith
      David Smith Staff June 14, 2014 at 8:22 am

      When you say a custom input do you mean a custom field type that you are creating via GF hooks?

    2. Elyssia
      Elyssia June 14, 2014 at 1:33 pm

      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.

    3. David Smith
      David Smith Staff June 14, 2014 at 2:32 pm

      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”.

    4. Elyssia
      Elyssia June 15, 2014 at 12:23 pm

      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?

    5. David Smith
      David Smith Staff June 15, 2014 at 8:54 pm

      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!

  11. John Burton
    John Burton May 22, 2014 at 2:12 pm

    Hi, It sure seems to be quite straight forward, but for some reason it’s not working for me.

    1. David Smith
      David Smith Staff May 22, 2014 at 3:57 pm

      Hi John, thanks for letting me know via email that you got this resolved. :)

  12. Tarequl Islam
    Tarequl Islam March 27, 2014 at 7:27 am

    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.

  13. Greg
    Greg February 20, 2014 at 5:14 am

    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.

  14. Bet Hannon
    Bet Hannon February 10, 2014 at 5:36 pm

    Very cool! I will definitely be using this– have several client forms with 100+fields (long camp registration forms)

  15. Andrew Blackburn
    Andrew Blackburn February 6, 2014 at 4:09 pm

    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.

  16. Simon
    Simon February 3, 2014 at 7:27 pm

    Genius! One of my customers has a 12 page form with multiple conditionals that all need testing, it’s been driving me nuts.

Comments are closed.

Download Snippet

Speed Up Your Gravity Forms Testing: Unrequire Required Fields

This field is for validation purposes and should be left unchanged.