Using Gravity Forms ‘gform_form_pre_results’ PHP filter

The gform_form_pre_results filter allows you to modify the Form object before the results are calculated in the admin results page. This is primarily used by add-ons implementing the Add-On Framework.

Usage

add_filter('gform_form_pre_results', 'your_function_name');

To target a specific form, add the form ID after the hook name:

add_filter('gform_form_pre_results_10', 'your_function_name');

Parameters

  • $form (array): The form object.

More information

See Gravity Forms Docs: gform_form_pre_results

Examples

Add field ID to field labels

This example adds the field ID to the field labels.

add_filter('gform_form_pre_results', 'modify_results_fields');

function modify_results_fields($form) {
    foreach ($form['fields'] as &$field) {
        $field['label'] .= sprintf(" (Field ID: %d)", $field['id']);
    }
    return $form;
}

Change the form title

This example changes the form title.

add_filter('gform_form_pre_results', 'change_form_title');

function change_form_title($form) {
    $form['title'] = 'New Form Title';
    return $form;
}

Remove a specific field from results

This example removes a field with ID 5 from the results.

add_filter('gform_form_pre_results', 'remove_field_from_results');

function remove_field_from_results($form) {
    foreach ($form['fields'] as $key => $field) {
        if ($field['id'] == 5) {
            unset($form['fields'][$key]);
        }
    }
    return $form;
}

Add a custom CSS class to form fields

This example adds a custom CSS class to all form fields.

add_filter('gform_form_pre_results', 'add_custom_css_class');

function add_custom_css_class($form) {
    foreach ($form['fields'] as &$field) {
        $field['cssClass'] .= ' custom-css-class';
    }
    return $form;
}

Update form button text

This example updates the form button text.

add_filter('gform_form_pre_results', 'update_button_text');

function update_button_text($form) {
    $form['button']['text'] = 'Updated Button Text';
    return $form;
}