Hi, see there’s a few bits and pieces that come up when doing a Google search, but all old and not really a solution. Our form field question is asking for the names of co-freeholders for a block of flats, but often only one person’s name is supplied. There should be at least 2, so hoping can set the minimum number of rows required to 2.
The filter gform_field_value_$parameter_name can be used to set an initial number of rows that are set for a list. For a single column list, the following would suffice…
Please forgive my ignorance, as self-teach here. I posted 17. List field validation into snippets functions.php, changing the form ID and field number. Please let me know what validate_list_field' `, 10, 4 ); means?
Then I pasted your code above into snippets first, then to form settings, custom Javascript and on both occasions nothing happened. In fact it disabled some of the code already there. Clearly I haven’t done it right, and would really welcome any assistance.
The code provided is PHP code. As such, you’ll need to add it via functions.php or a PHP code snippets plugin – sounds like the fist place you had placed it. The validation function will only run upon form submission, ensuring all cells of the list field are filled before submission is allowed.
In order for the small snippet I provided above to have any effect (i.e. default the list to two rows from the get-go), you will need to not only add the code to a snippet, but also set list_two_rows as the value for List → Field Settings → Advanced → Allow field to be populated dynamically → Parameter Name.
Your code in your first message wasn’t accepted in snippets.
I added in parameter name list_two_rows.
It’s not working, down to me and being a novice surely not doing it right. Joshua thank you for your patience, hoping you can let me where I continue to go wrong?
Thanks for your time Joshua.
I added the following to snippets php:
add_filter( ‘gform_field_value_list_two_rows’, function( $value ) {
return [
array(),
array()
];
} );
Under the field list, parameter name, added: list_two_rows
This is a 3 column list field.
It’s not working, so can I please ask for a little more assistance, and no doubt patience, as know can’t be easy dealing with queries from people like me with very little know-how.
Ensure the single-quotes around the filter name are basic single-quotes 'gform_field_value_list_two_rows' and not curly quote ‘gform_field_value_list_two_rows’. Your reply above seems to have them copied as curly.
If using the code snippets plugin, make sure the snippet is set to run across the whole site and not only in the admin.
Beyond that you would probably need to add some logging statements to the snippet to first ensure the code is indeed being run or may want to connect with someone that can log in to the site and investigate further.
Thanks, to re-cap I’ve only done the following, no curly quotes, snippets, allow everywhere:
add_filter( ‘gform_field_value_list_two_rows’, function( $value ) {
return [
array(),
array()
];
} );
Field applying to, advanced, Parameter name: list_two_rows
Not done anything else and despite your kind help it isn’t working. Finally if there’s something else I need to do please advise?