Using Gravity Forms ‘gform_form_switcher_forms’ PHP filter

The gform_form_switcher_forms filter allows you to modify the forms displayed in the Form Switcher dropdown in Gravity Forms.

Usage

add_filter('gform_form_switcher_forms', 'your_custom_function', 10, 1);

function your_custom_function($forms) {
    // your custom code here
    return $forms;
}

Parameters

  • $forms (array): Array containing all forms, sorted by title.

More information

See Gravity Forms Docs: gform_form_switcher_forms

Examples

Display First Ten Forms

Limit the Form Switcher dropdown to display only the first ten forms.

add_filter('gform_form_switcher_forms', 'limit_form_switcher_forms', 10, 1);

function limit_form_switcher_forms($forms) {
    return array_splice($forms, 0, 10);
}

Exclude a Specific Form

Exclude a specific form by ID from the Form Switcher dropdown.

add_filter('gform_form_switcher_forms', 'exclude_specific_form', 10, 1);

function exclude_specific_form($forms) {
    $form_id_to_exclude = 5;

    return array_filter($forms, function ($form) use ($form_id_to_exclude) {
        return $form['id'] != $form_id_to_exclude;
    });
}

Display Forms by Title Keyword

Display only forms that have a specific keyword in their title.

add_filter('gform_form_switcher_forms', 'filter_forms_by_title_keyword', 10, 1);

function filter_forms_by_title_keyword($forms) {
    $keyword = 'survey';

    return array_filter($forms, function ($form) use ($keyword) {
        return strpos(strtolower($form['title']), strtolower($keyword)) !== false;
    });
}

Display Forms with a Minimum Number of Fields

Display only forms with a minimum number of fields.

add_filter('gform_form_switcher_forms', 'filter_forms_by_field_count', 10, 1);

function filter_forms_by_field_count($forms) {
    $min_fields = 3;

    return array_filter($forms, function ($form) use ($min_fields) {
        return count($form['fields']) >= $min_fields;
    });
}

Sort Forms by Created Date

Sort forms in the Form Switcher dropdown by their created date.

add_filter('gform_form_switcher_forms', 'sort_forms_by_created_date', 10, 1);

function sort_forms_by_created_date($forms) {
    usort($forms, function ($a, $b) {
        return strtotime($a['date_created']) - strtotime($b['date_created']);
    });

    return $forms;
}