fluenform_rendering_field_data_select

Description #

To populate dropdown filter with your own custom values use this filter. For example post types, user name.

$data = apply_filters('fluenform_rendering_field_data_select', $data, $form);

Usage #

The following code will add two new options to your drop down field. Here we have used the dropdown input name attribute as ‘dynamic_dropdown’, make sure it matches with your attribute name. This snippet will run for the form id with 91.

For example, we have passed an array of two values, in 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('fluenform_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);

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

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *