fbpx

Sometimes when you’re populating a dynamic field with information from another form’s entries, you only want certain ones – like entries where another field matches some criteria or other.

In cases like that, do this:

function filter_dfe_options($values, $field){
	// Filter dfe entries list to only include 'something' entries
    if ( $field->id == 1181 && !empty( $values['options'] ) ) { //Replace 1181 with the ID of your dfe field
        $temp = $values;
        $temp['form_select'] = 30; //change 30 to the id of the field (in linked form) that you want to filter by
        $field2_opts = FrmProFieldsHelper::get_linked_options( $temp, $field );
        foreach ( $values['options'] as $id => $v ) {
            if ( isset( $field2_opts[$id] ) && ( $v == '' || $field2_opts[$id] == 'something' ) ) {
              // Optional: only include values where filtering field equals "something"
                continue;
            }
            unset( $values['options'][$id] );
        }
    }
    return $values;
}
add_filter('frm_setup_new_fields_vars', 'filter_dfe_plan_options', 25, 2);

%d bloggers like this: