Description #
To populate the dropdown filter with your own custom values use this filter. For example post types, user name.
$data = apply_filters('fluentform/rendering_field_data_select', $data, $form);
Usage #
The following code will add two new options to your dropdown field. Here we have used the dropdown input name attribute as ‘dynamic_dropdown’, make sure it matches your attribute name. This snippet will run for the form id with 91.
For example, we have passed an array of two values, here you can pass your own data, you can use WP_Query or another way to fetch your data but it needs to match the data format as shown in the example.
add_filter('fluentform/rendering_field_data_select', function ($data, $form) {
if ($form->id != 91) {
return $data;
}
// check if the name attriibute is 'dynamic_dropdown'
if (\FluentForm\Framework\Helpers\ArrayHelper::get($data, 'attributes.name') != 'dynamic_dropdown') {
return $data;
}
// We are merging with existing options here
$data['settings']['advanced_options'] = array_merge($data['settings']['advanced_options'], [
[
"label" => "Dynamic Option 1",
"value" => "Dynamic Option 1",
"calc_value" => ""
],
[
"label" => "Dynamic Option 2",
"value" => "Dynamic Option 2",
"calc_value" => ""
]
]);
return $data;
}, 10, 2);
If you use this you will also need the following code, which bypass the select backend validation for inserting datas that are not present in fluent form database.
add_filter('fluentform/validate_input_item_select',function ($error,$field){
return [];
},10,2);
Parameters #
- $data Array ( input field settings & attributes)
- $form Object
Placement #
This code should be placed in the functions.php file of your active theme or you can use a PHP code snippet plugin.
Source Code #
This filter is located at fluentform/app/Services/FormBuilder/Components/Select.php