I just need a simple example how to dynamically populate the list field during a pre_render.
I just need a simple example how to dynamically populate the list field during a pre_render.
You wouldn't use the pre_render hook in this situation. You would dynamically populate a list field using the gform_field_value_$parameter_name filter which is documented here:
http://www.gravityhelp.com/documentation/page/Gform_field_value_$parameter_name
You would first need to set the field so that it can be populated dynamically and give it a parameter name. You do this by editing the form and then editing your list field. The dynamic population option is under the Advanced tab.
The following is a sample snippet that will help you with the data format. This example assumes you used "list" as the parameter name for that field and that it is a multi-column list field. You can customize it to suit your needs (single column, more columns, less columns, etc.).
add_filter("gform_field_value_list", "populate_list");
function populate_list($value){
return array("row 1 - col1","row 1 - col2", "row 1 - col3",
"row 2 - col1", "row 2 - col2", "row 2 - col3",
"row 3 - col1", "row 3 - col2", "row 3 - col3");
}
There is also a How To page on how to dynamically populate fields using the same filter, although it doesn't use a List Field as an example. You can find that How To here:
http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population