Last active
November 16, 2022 06:39
-
-
Save aimahdi/218198d1ecd401ba1847bdf10a154a88 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('fluentform_rendering_field_data_select', function ($data, $form) { | |
$targetFormID = 2; | |
//google sheet shared as CSV link | |
$csvUrl = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vSQM0ay3KgEmTp64M7ZZ5n5QXHDsSzaaJcVCuIHBvgMIw32foNpdfd4jNnUMua8b5Mavb6E4jox_nic/pub?output=csv'; | |
$columName = 'Opex Vessel Categories'; // 'Players' is the column name | |
$uniqueData = false; // 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])) { | |
$value = ""; | |
for($i=0; $i<sizeof($row); $i++){ | |
$value = $value." ".$row[$i]; | |
} | |
$result[]= [ | |
"label" => $value, | |
"value" => $row[$headerIndex], | |
"calc_value" => "" | |
]; | |
} | |
} | |
$result = ($uniqueData === true) ? array_map("unserialize", array_unique(array_map("serialize", $result))) : $result; | |
// Merging with existing options here | |
$data['settings']['advanced_options'] = array_merge($data['settings']['advanced_options'], $result ); | |
return $data; | |
}, 10, 2); |
Hello Taliabiasevi,
You need to combine the code in below conditional blocks
if ($form->id != 21 &&
\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') !=
'dropdown') {
return $data;
}
else if ($form->id != 22 &&
\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') !=
'dropdown_1') {
return $data;
}
Make sure, you have used a different name attribute on the dropdown.
Sincerely,
*Amimul Ihsan*
*Mobile Application Developer*
…On Mon, Nov 14, 2022 at 11:53 PM Taliabiasevi ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi Aimahdi!
I have a list that I want to use as a dropdown in 3 forms.
How would you use this code to include the dropdown in several forms? Is
it possible? Or should I repeat the whole code entirely and change the Form
ID?
Many thanks!!!
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/218198d1ecd401ba1847bdf10a154a88#gistcomment-4369070>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AF5WQXT3TKETOVRB4MA5I7DWIJ4C7BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMZVGI2TCMJUU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored a thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Aimahdi!
I have a list that I want to use as a dropdown in 3 forms.
How would you use this code to include the dropdown in several forms? Is it possible? Or should I repeat the whole code entirely and change the Form ID?
Many thanks!!!