Can I ask you to share your solution? What did you add to the functions file?
Thank you.
Sorry that it took so long; here it is. You get the skeleton of the function by clicking on “Filter custom options” in the grid editor, as explained in the video.
It will look somehow like the first lines below. Just create the skeleton in the grid editor, paste it to functions.php and the copy&paste the respective parts from the code below. Of course adapth path and file name.
add_filter( 'cf7sg_dynamic_dropdown_custom_options','my_list_dynamic_options',10,3);
function my_list_dynamic_options($options, $name, $cf7_key){
if('list-dynamic'!==$cf7_key || 'my-list' !== $name){
return $options;
}
//these are the label users will see when the dropdown opens.
//you can group your options if need be. Let's assume you have an array of arrays of data to display in groups.
//$data = ... //fetch your data, either from the database or some other source.
$uploads_folder = "./path/to/file/"; ## relative path to your file, incl. closing slash
$filename = "abc.csv"; ## name of file
try
{
$file = fopen($uploads_folder.$filename, 'r'); ## tries to open the file
if (! $file)
{ //if that fails...
throw new Exception("File could not be opened!" . $uploads_folder.$filename);
}
}
// error output
catch (Exception $e)
{
echo "Error (File: ".$e->getFile().", line ".
$e->getLine()."): ".$e->getMessage();
}
$data = array();
### each line of the csv is a pair of values in the array, line[0] is the first column, line[1] is the second, separated by ";" (if the csv has multiple columns)
if ( $file)
while (($line = fgetcsv($file, 0, ";")) !== FALSE)
{ // until end of file
$data[$line[0]] = $line[0];
}
if ($file)
fclose($file);
foreach($data as $value)
{
$options .= '<option value="'.$value.'">'.$value.'</option>';
}
return $options;
}