Skip to content

Instantly share code, notes, and snippets.

@aimahdi
Last active March 22, 2023 07:20
Show Gist options
  • Save aimahdi/b1ce71fe066e1dbb98507cd2d429edc9 to your computer and use it in GitHub Desktop.
Save aimahdi/b1ce71fe066e1dbb98507cd2d429edc9 to your computer and use it in GitHub Desktop.
add_filter('fluentform_rendering_field_data_select', function ($data, $form) {
$targetFormID = 15;
//google sheet shared as CSV link
$csvUrl = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vT-mQ_isy2CXOi70SjjbNaCPbmhmshikUS8o3nEthE2N-6NsqdABnW6Crlmb2DegaO6IsM9QcjlWPz4/pub?output=csv';
$columName = 'Processos ativos'; // 'Players' is the column name
$uniqueData = true; // remove duplicate values
if ($form->id != $targetFormID) {
return $data;
}
// check if the name attribute is 'dropdown' , it is by default dropdown for the first dropdown input
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'dropdown') {
return $data;
}
$result=[] ;
if (!class_exists('CSVParser')) {
require_once(FLUENTFORMPRO_DIR_PATH . 'libs/CSVParser/CSVParser.php');
}
$csvParser = new \CSVParser;
$content = file_get_contents($csvUrl);
$csvParser->load_data($content);
$rows = $csvParser->parse($csvParser->find_delimiter());
if(!$rows) {
return $data;
}
$headers = array_shift($rows); // remove the first item
$headerIndex = array_search($columName, $headers);
foreach ($rows as $row) {
if(!empty($row[$headerIndex])) {
$myValue = implode(" ", $row);
$result[]=
[
"label" => $myValue,
"value" => $myValue,
"calc_value" => ""
];
}
}
$result = ($uniqueData === true) ? array_map("unserialize", array_unique(array_map("serialize", $result))) : $result;
$data['settings']['advanced_options'] = $result;
return $data;
}, 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment