Using Gravity Forms ‘gform_form_update_meta’ PHP action

The gform_form_update_meta filter allows modifying the form meta before it is saved to the database in Gravity Forms.

Usage

A generic example of how to use the filter for all forms:

add_filter('gform_form_update_meta', 'my_custom_function', 10, 3);

To target a specific form, append the form ID to the filter name (format: gform_form_update_meta_FORMID):

add_filter('gform_form_update_meta_1', 'my_custom_function', 10, 3);

Parameters

  • $form_meta (string) – The meta data for the current form.
  • $form_id (int) – The current form ID.
  • $meta_name (string) – Meta name.

More information

See Gravity Forms Docs: gform_form_update_meta

Examples

Mark a form as imported

This code marks a form as imported by adding an ‘isImported’ key to the form meta.

function mark_form_as_imported($form_meta, $form_id, $meta_name) {
    if (GFForms::get_page() != 'import_form' || $meta_name != 'display_meta') {
        return $form_meta;
    }
    $form_meta['isImported'] = true;
    return $form_meta;
}
add_filter('gform_form_update_meta', 'mark_form_as_imported', 10, 3);

Add a custom class to a form

This code adds a custom CSS class to a specific form with ID 1.

function add_custom_class($form_meta, $form_id, $meta_name) {
    if ($meta_name != 'display_meta') {
        return $form_meta;
    }
    $form_meta['cssClass'] = 'my-custom-class';
    return $form_meta;
}
add_filter('gform_form_update_meta_1', 'add_custom_class', 10, 3);

Disable AJAX for a specific form

This code disables AJAX for a form with ID 2.

function disable_ajax($form_meta, $form_id, $meta_name) {
    if ($meta_name != 'display_meta') {
        return $form_meta;
    }
    $form_meta['enable_ajax'] = false;
    return $form_meta;
}
add_filter('gform_form_update_meta_2', 'disable_ajax', 10, 3);

Set a form’s background color

This code sets the background color for a form with ID 3.

function set_form_background_color($form_meta, $form_id, $meta_name) {
    if ($meta_name != 'display_meta') {
        return $form_meta;
    }
    $form_meta['backgroundColor'] = '#f5f5f5';
    return $form_meta;
}
add_filter('gform_form_update_meta_3', 'set_form_background_color', 10, 3);

Change form’s submit button text

This code changes the submit button text for a form with ID 4.

function change_submit_button_text($form_meta, $form_id, $meta_name) {
    if ($meta_name != 'display_meta') {
        return $form_meta;
    }
    $form_meta['button']['text'] = 'Send My Information';
    return $form_meta;
}
add_filter('gform_form_update_meta_4', 'change_submit_button_text', 10, 3);