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.
new GWRequireListColumns();
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:
new GWRequireListColumns(4);
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.
Summary
This can be conveniently used in combination with the Set Number of List Field Rows by Field Value snippet.
Did this resource help you do something awesome with Gravity Forms? Then you'll absolutely love Gravity Perks; a suite of 32+ essential add-ons for Gravity Forms with support you can count on.
Hi there It’s not working in gravity flow steps!!
Hello ! Very nice snippet but the validation works only on the first row. If i add another row i can go to the next step of my form without filling fields of the second row while it’s required.
Do you have an idea of what could be the problem ?
Thank’s a lot for your snippet !
Hi Alexis, I’m not able to recreate this issue on the demo: https://gravitywiz.com/require-all-columns-of-list-field/
If you’re a Gravity Perks customer, we’ll be happy to provide additional support via the support form.
Hi,
We tried to implement this code on our website but it only checks the first row. Whenever I add a new row it doesn’t validate it. See issue on: http://tandarts.100test.nl/coming-soon/. The list field is placed on the third page ‘Opmerkingen’. Could you please help us out?
Thanks in advance!
This is very similar to a recent issue reported by one of our Gravity Perks customers with this snippet. Here is our response to him:
Works like magic, but i have two limitations or issues with it.
The code is too long, i prefer something shorter and simple.
The error message highlights all the whole lists, instead of highlighting the affected rows, or colums only. And it can be very tasking for a list of over 250 rows.
Thanks for the feedback, Chris. The code is as long as it needs to be to meet the requirements. As for the highlighting the affected rows/columns, this is feasible but would require some considerable customization as Gravity Forms only provides field-level validation but not row-level. We’ll monitor demand for such an enhancement. 🙂
Hi! I am using this on a website and it had been working fine to my knowledge but the client requested that one column not be required so I used the code to require specific columns, but it doesn’t seem to be working. Users are now able to submit with an entirely blank row. Any ideas? Here is my code:
new GWRequireListColumns(2, 7, array( 1, 2, 3 ) );
and here is an example form:
http://www.scltap.org/event-registration/?e=5336
Thank you!
Joel
Are you able to recreate on the demo?
I see that it is working in the demo and I believe I resolved the issue. I believe the code on the website was an older version of this. I updated that and I believe that fixed it. Thanks David!
Glad to hear it, Joel. ?
how to build a list dynamically that you have both text boxes and drop dow?
colum1 colum2 colum3 input drop down input
We recommend GF Nested Forms for collecting advanced, repeatable data: https://gravitywiz.com/documentation/gravity-forms-nested-forms/
Can you please help sort out this issue? I’m getting an error after submitting my form:
Warning: Invalid argument supplied for foreach() in /home/jcres/public_html/processes/wp-content/plugins/process-functionality-plugin/functionality-plugin.php on line 852
The code on line 852 is:
foreach($values as $value) { if(empty($value)) { $new_validation_error = true; $field[‘failed_validation’] = true; $field[‘validation_message’] = $field[‘errorMessage’] ? $field[‘errorMessage’] : ‘All inputs must be filled out.’; } }
This snippet seems not working after upgrading to Gravity Forms 2.3.1, please check it.
Hi Edi, drop us a line via support and we’ll be happy to dig in.
Hello David, We have a list that has almost 200 rows; is there a way to have it actually highlight the row that is actually failing validation?
We don’t currently have a solution for this one, Jeremy.
Thanks, I tackled from the client side after all. Glad to see you added support for the List Fields.
Hello and thanks I copy this code to functions.php of my theme and use new GWRequireListColumns(); but it doesn’t work. None of the fields are required. please help me
Hi Moshtaghi, the demo is still working so there is mostly likely a configuration issue or conflict on your end. You can start with a theme/plugin conflict test. If that doesn’t turn anything up and you’re a Gravity Perks customer, we’ll be happy to provide additional support via the support form.
Hello,
I am trying this snippet on my website but it seems to break the website. I pasted the code in functions.php and the site goes blank. Appreciate any help.
Hi Brijesh, try this: https://gravitywiz.com/documentation/snippet-troubleshooting/
thank you! it worked in the first try!
Glad to help, Alejandro. :)
Thanks for this code! Seems to trip up when there is more than one list on the form and the required-rules are different for each.
Can you help me make this work?
eg – List 1 needs columns 1, 2 & 3 as mandatory – List 2 needs columns 1, 4 & 5 as mandatory
Thanks!
Hey Joe, can you send me an export of your form and your configuration of the snippet?
Hi there,
I’ve installed the code from the download link to the functions file, and am utilizing the “Require Specific Columns on a Group of Fields”. It’s not working for me. Do I need to comment out the other classes or how can I get this to work?
It’s on the “select product type” field and first checkbox “roller shade”
http://shadesbymatiss.com/advanced-order-form
password is: matiss.
Not to worry this is only a test form. THanks!
Hi James, you’ll need to enable the Required setting for this field in the form editor field settings as well.
thank worked! thank you!
Hi David, This doesn’t seem to work when the Save & Continue Button is used. If you access the form via the Resume link the fields are no longer mandatory.
Thanks
Hi Justin, I’ve just tested this on my end and the requirement is still enforced. It sounds like this might be specific to configuration. I’d try a theme/plugin conflict as a next step.
Hi,
Thank you for providing the code to accomplish this! One issue I’m running into is whenever I add this code and submit a form without all the list columns filled in, I get a “jQuery is not defined” console error, which messes up some jQuery code I have on the form. This console error is not there before submitting the form.
The form validation works perfectly, just curious what could be causing this console error to appear after submitting the form.
Any idea of why this may be happening?
Thanks again!!
Do you have a URL and/or form export I could see with this issue intact?
Hey David,
Here is a link to the form: http://corprisk.staging.wpengine.com/products/nerc-cip-compliance-guide/
If you scroll down, choose the “PDF Version” option then “Click Here to Order”. After that, click the “I have read and agree to the terms and conditions.” and the Checkout button should appear.
If you try to submit the form without filling out all the fields, the Terms and Conditions opens up and I’m getting the “jQuery is not defined”. I’m using another plugin called Collapse-O-Matic (https://wordpress.org/plugins/jquery-collapse-o-matic/) for the Terms and Conditions accordion function.
If the issue is the Collapse-O-Matic plugin, I can figure out a different route, I just wanted to make sure it was nothing with the code I added to require all list fields.
Thanks for looking into this!
Hi Blake, sorry for the long wait. I see the issue and yes this is generated by the snippet + AJAX enabled forms. I’m going to hold off on addressing this for now but if more people are attempting to use this in the same way, I will revisit.