[FORMINATOR] Forminator filter

I wanted to know if there is a hook I can use to customise the options in a forminator select field.

I have a list of options nearly 25 to 30 and they keep changing.

For the select fields i want to get the options from a query like $wpdb->get_results("select id,options from {$wpdb->prefix}custom_table");

Can you let them know that if they can add a filter in the file : forminator/library/fields/select.php at line number 146... $options = apply_filters('forminator_field_select_options',$id,$options)

that would solve the problem.

  • Kostas
    • CTO

    Hi Kashi , sorry for the late reply.

    That seems like a good spot to add a filter as you have it since you want to alter the options before the rendering process starts. We would normally do it in before the front-end as you stated also via the forminator_field_markup that also includes the form id as well.

    As a very loose example for reference it could be done with something like:

    add_filter(
    'forminator_field_markup',
    function( $html, $field, $form ) {

    if ( 12 === $form->model->id && 'select-1' == $field['element_id'] ) {
    $html = '<div class="forminator-field--label">';
    $html .= '<label id="forminator-label-select-1-field" class="forminator-label">Select</label>';
    $html .= '</div>';
    $html .= '<select class="forminator-select--field forminator-select" id="select-1-field" data-required="" name="select-1">';

    // WP_Query here to add <option> fields to $html.

    $html .= '</select>';
    }

    return $html;
    },
    15,
    3
    );

    I’ll inform our Developers in case we could add more filters in earlier parts of the process as the one you needed in a future release as well.

    Regards,

    Konstantinos