April 26, 2022: Fixed issue where requiring specific columns did not apply to subsequent rows (again).
December 12, 2020: Fixed an issue where require list columns would fail validation if '0' is submitted.
July 14, 2015: Fixed issue where requiring specific columns did not apply to subsequent rows.
January 7, 2015: Added support any field with an input type of List field; this provides support for using this snippet with Post Custom Fields with an input type of List.
October 22, 2013: Updated to support a $require_columns parameter. Allows requiring specific columns rather than all columns on a list field.
September 13th, 2012: Updated to use a class format to allow you to apply this functionality to a specific form and/or specific fields.
When you mark a List field as required, only a single input from any column is required. What if you want every input in every column to be required? Here is a snippet that let’s you do it.
How do I install this snippet?
Just copy and paste the code above in your theme’s ”functions.php” file.
Do I need to configure this snippet to work with my form(s)?
Require All Columns on All Forms
Only if you want to apply this functionality to specific forms and/or specific fields. A default instantiation of this class (with no parameters) will apply this functionality to all list fields on all forms.
Require All Columns on a Specific Form
To apply this to a specific form, you would simply pass the form ID as the first parameter:
Require All Columns on a Specific Field
To apply this functionality to a specific form and a specific List field on that form, you would specify the form ID as the first parameter and the field ID as the second:
new GWRequireListColumns(4, 2);
Require All Columns on a Group of Fields
To apply this functionality to a specific form and multiple List fields on that form, you would specify the form ID as the first parameter and an array of fields IDs as the second parameter:
new GWRequireListColumns(4, array(2,3) );
Require Specific Columns on a Group of Fields
To require specific columns on a specific field, you would specific the form ID, the field ID and the specific columns (by index, starting with 1) you would like to require:
new GWRequireListColumns( 240, 1, array( 2, 3 ) );
Note: If you have used
new GWRequireListColumns() to require all columns on all fields, you can override which columns are required for a specific field by passing the $require_columns parameter in a new instance of this class.
It can also count the number of List field rows and use that value in Gravity Forms List field calculations!
This can be conveniently used in combination with the Set Number of List Field Rows by Field Value snippet.