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.
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.
It can also count the number of List field rows and use that value in Gravity Forms List field calculations!
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 46+ essential add-ons for Gravity Forms with support you can count on.
Has this been tested with GravityKit’s GravityView plugin? This works fine when submitting a form however we’ve found it doesn’t enforce the required setting when the user chooses to edit the entry in GravityView.
Hey Natalie, I confirmed that this is working in GravityView:
It’s possible something else is conflicting?
Sorry, this just isn’t working for me, but maybe I’m not using it correctly. Do I need to add a “GWRequireListColumns” class to the form or the fields themselves? Or do I need a GravityWiz plugin or account before this works? Just putting this code in my functions.php file has no effect.
sorry, you can remove my comment. i missed a key component. All works as expected. Thanks!
Hi Dan,
Did you also include the full code snippet in your functions.php file? You need both that and
GWRequireListColumns
class.May I suggest you put this “Leave a Reply” section at the top of the comments? And shouldn’t it be named “Leave a Comment”? Reply to what? And your submit button says “Post Comment”. I didn’t think I could post a new comment because I couldn’t imagine having to scroll to the very bottom of what could have been an extremely long list of comments.
Or at least post a link to this section at the top of the comments.
Also, I have checked to receive emails from followup comments but I’ve never received one. There’s nothing in my Spam folder either.
Thanks.
Hi John,
Thanks for the feedback. I’m going to share it with our developers.
I just tested the comment emails, and emails are arriving in my inbox. I suggest reaching out to your email provider about this.
Hi Vinod,
This looks like a question that will require some digging.
If you have an active Gravity Perks License, can you please get in touch with us via our support form with your account email address so we can assist you further.
Best,
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.
The Demo doesn’t work properly either. The Player’s field only needs the first row of required fields filled. Aside from all columns instances, this only works on the first row for me as well.
Hi John,
You sent in multiple comments with the same issue so we approved one. That said, I’m unable to recreate the issue you’re reporting. I just tested the demo and it works correctly. The required columns work on every row and not just the first row. The player list field has the first, second and fourth column as required so the configuration will be something like so: new GWRequireListColumns( 123, 4, array( 1, 2, 4 ) );
You can get in touch with us via our support form if you have an active Gravity Perks license, so we can take a look at your setup and assist you to set it up.
Best,
I’ve replied multiple times yet none of them show up. Are they being rejected?
The Demo doesn’t work the same way the snippet doesn’t work for anything but all columns. For a specific column(s) it only works for the first row. Any response?
Hi,
We’ve already replied to the comments you sent earlier. You can check it out here.
Best,
I apologize for submitting another duplicate reply. I only see my replies after I submit a reply. Even after I refresh the page I don’t see them so I post another.
Did you fill out the demo as follows? All Coach fields in all rows filled in. It only works if all fields filled in. Only 1st row of multiple Player rows are filled in for fields 1, 2, 4.
If the first Player row is not filled in as described then i correctly get the validation error. But I can fill in that row and leave all the other rows empty and submit successfully.
This mirrors what happens on my site. How do you track multiple rows of data? Do you get/need the length of the list?
It’s easy to validate everything. It seems there’s a bug when there are specific fields in multiple rows.
How can the Demo work differently for different people?
Hi John,
It seems to work on the demo page when testing with the data you provide and when testing locally. You can get in touch with us via our support form if you have an active Gravity Perks license, so we can take a look at your setup and assist you to set it up.
Cheers,
Dario, that’s the point: it should NOT work with the data I provided. Shouldn’t it fail validation if ALL Player rows are not filled in for inputs 1, 2, 4?
What do you mean by “it works”, that it submits successfully with empty Player rows or fails validation with empty Player rows?
Thanks.
Hi John,
We’ve finally been able to recreate the issue with the demo and snippet. I’ll pass this over to our developers to dig into it. We’ll update the comment section when this is resolved.
Best,
The release note at the top of this article says:
“July 14, 2015: Fixed issue where requiring specific columns did not apply to subsequent rows.”
That was 7 years ago. This seems to be the very issue we’re discussing. Was this fix undone by futures fixes or did this fix ever actually work?
Thanks.
Hi John,
Yes, it appears to be the same issue that was fixed but that was in 2015 and over the years, Gravity Forms has evolved. I’m guessing one of the recent Gravity Forms versions may have broken the code. This has been forwarded to our developers to look into. We’ll update the comment and release note to let everyone know when the issue is resolved.
Best,
This issue has been resolved.
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.