Quantcast
Channel: Snippets Archives - Gravity Wiz
Viewing all articles
Browse latest Browse all 196

Speed Up Your Gravity Forms Testing: Unrequire Required Fields

$
0
0

Stop! There's a better way.

This snippet is available as a plugin with Gravity Perks, a suite of over 31 premium Gravity Forms plugins!

View this code snippet on GitHub.

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

How do I get started?

  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.

View this code snippet on GitHub.

Enable for All Users (including visitors)

Allows you to unrequire fields without being logged in. Not advisable for live servers.

View this code snippet on GitHub.

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.

View this code snippet on GitHub.

Parameters

  • admins_only (bool) Only allow administrators to bypass required fields. Defaults to true.
  • require_query_param (int) 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!


Viewing all articles
Browse latest Browse all 196

Trending Articles