How to Add a ā€œNone of the Aboveā€ option to your Checkbox Field

Learn how to create a ā€œNone of the Aboveā€ checkbox. When ā€œNone of the Aboveā€ is selected, all other options are disabled. When any other option is selected, ā€œNone of the Aboveā€ is disabled.

add a none of the above field in gravity forms

Imagine youā€™re a marketer at your company, and youā€™re looking to get feedback on which types of social media your users prefer. You could create a form and show each type as a checklist. It would also be nice to give users a ā€œNone of the Aboveā€ option, just in case they donā€™t like any of the options. But, what happens if a user chooses several options and ā€œNone of the Aboveā€ at the same time? It can get confusing, very quickly:

Thankfully, thereā€™s a smarter way to handle this scenario with this snippet. By following the steps below, youā€™ll be able to add a ā€œNone of the Aboveā€ option to your checkbox field that works like this:

  • When ā€œNone of the Aboveā€ is selected, all other choices are disabled.
  • When any other choice is selected, the ā€œNone of the Aboveā€ option is disabled.
  1. Steps
    1. Step 1 ā€“ Install the ā€œNone of the Aboveā€ Snippet
    2. Step 2 ā€“ Add the Form Fields
    3. Step 3 ā€“ Add Custom CSS
  2. Taking it Further

Steps

Step 1 ā€“ Install the ā€œNone of the Aboveā€ Snippet

Weā€™ll start by installing this custom snippet. Since itā€™s a JavaScript snippet, we recommend using the free Gravity Forms Code Chest plugin. This is a plugin we made that makes it easy to add JavaScript snippets to your forms.

Once the plugin is installed, navigate to your Form Settings. Copy all of the text from the snippet file into the Custom Javascript text box:

install none of the above snippet

Step 2 ā€“ Add the Form Fields

Next, build your form and add your fields as normal. Add a Checkbox field with all of the choices you want your users to pick from. Be sure to add ā€œNone of the Aboveā€ as the last choice:

add a checkbox field to all choices

Step 3 ā€“ Add Custom CSS

Finally, weā€™ll add a CSS class to the Checkbox field so the snippet knows which field to target. Click on the Checkbox field and add this text to the Custom CSS Class field under the Appearance header: gw-none-of-the-above.

add custom css

You can add this CSS class to as many Checkbox fields as youā€™d like.

Taking it Further

To check if the choices we display are relevant to users, we can count how many times ā€œNone of the Aboveā€ was selected. A high count may indicate that we should reconsider which options weā€™re displaying.

First, weā€™ll start by adding a Number field called ā€œNone of the Above countā€ to our form. Weā€™ll set this field to be hidden from users. Take note of the field ID in the top right corner ā€“ weā€™ll need this later:

none of the above count field in gravity forms

Once the number field is created, weā€™ll install this custom snippet. Since this snippet is a PHP snippet, the install process is slightly different than the ā€œNone of the Aboveā€ snippet. Take a look at our instructions here that explain how to install a PHP snippet.

Add the following to the bottom of the snippet code:

new GW_Choice_Count( array(
	'form_id'          => 123,           // The ID of your form.
	'count_field_id'   => 2,             // Any Number field on your form in which the number of checked checkboxes should be dynamically populated; you can configure conditional logic based on the value of this field.
	'choice_field_ids' => 1, // Any array of Checkbox or Multi-select field IDs which should be counted.
	'values'           => array( 'None of the Above' ),         // Specify an array of values that should be counted. Values not in this list will not be counted. Defaults to `false` which will count all values.
) );

  • Replace form_id with your formā€™s ID.
  • Replace count_field_id with your Number fieldā€™s ID.
  • Replace choice_field_ids with your Checkbox field ID. You can use multiple field IDs in an array.
  • Replace values if youā€™re looking to include choices other than ā€œNone of the Aboveā€.

Check out the full article here for more information.

Comments

  1. Mike Orr
    Mike Orr May 18, 2023 at 12:02 pm

    Hi, I tried doing this but got the following error when adding the php snippet:

    Uncaught Error: Class ā€˜GW_Choice_Countā€™ not found in wp-content/themes/bb-theme-child/functions.php:2086 Stack trace:

    0 wp-settings.php(591): include()

    1 wp-config.php(118): require_once(ā€˜/home/charliesdā€¦ā€™)

    2 wp-load.php(50): require_once(ā€˜/home/charliesdā€¦ā€™)

    3 wp-admin/admin.php(34): require_once(ā€˜/home/charliesdā€¦ā€™)

    4 wp-admin/theme-editor.php(10): require_once(ā€˜/home/charliesdā€¦ā€™)

    5 {main}

    thrown

    Any ideas?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.


Grab a bundle of free Gravity Forms plugins

Enter your email and receive our most popular free plugins and snippets, plus access to hundreds of others.

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