gform_form_post_get_meta

Description

The gform_form_post_get_meta filter is applied to the Form Object after the form meta is retrieved from the database. This filter runs whenever Gravity Forms loads a form, making it a centralized hook for modifying form properties across all contexts (rendering, validation, submission, admin, etc.).

Note: Because this filter runs in multiple contexts, including form saving and form rendering, add conditions to prevent unintended modifications in the form editor or during save operations. For dynamic population that only affects form rendering, use the gform_pre_render filter instead which is the recommended approach for most use cases.

Usage

The following would apply to all forms.

add_filter( 'gform_form_post_get_meta', 'your_function_name' );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_form_post_get_meta_FORMID)

add_filter( 'gform_form_post_get_meta_123', 'your_function_name' );

Parameters

ParameterTypeDescription
$form Form ObjectThe current form to be filtered.

Examples

Return admin labels in REST API request.

The following example shows how a form, in this case id #93, can be configured to return admin labels when entries are retrieved via the REST API with the _labels argument.

add_filter( 'gform_form_post_get_meta_123', function ( $form ) {
    if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST  || ! rgget( '_labels' ) ) {
        return $form;
    }
 
    foreach ( $form['fields'] as $field ) {
        if ( $field->displayOnly ) {
            continue;
        }
        $field->set_context_property( 'use_admin_label', true );
    }
 
    return $form;
} );

Populate Choices Dynamically.

// Replace 123 with your form id
add_filter( 'gform_form_post_get_meta_123', 'populate_choices_from_posts' );

function populate_choices_from_posts( $form ) {

    // Don't modify when saving the form in admin
    if ( defined( 'DOING_AJAX' ) && DOING_AJAX && rgpost( 'action' ) === 'gf_save_form' ) {
        return $form;
    }

    // Don't modify in the form editor
    if ( GFCommon::is_form_editor() ) {
        return $form;
    }

    // Get posts from "Business" category
    $posts = get_posts( 'category=' . get_cat_ID( 'Business' ) );

    // Build choices array
    $choices = array();
    foreach ( $posts as $post ) {
        $choices[] = array( 'value' => $post->post_title, 'text' => $post->post_title );
    }

    // Apply choices to field ID 4
    foreach ( $form['fields'] as &$field ) {
        if ( $field->id == 4 ) {
            $field->choices = $choices;
            $field->placeholder = 'Select a business';
        }
    }

    return $form;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

$form = gf_apply_filters( 'gform_form_post_get_meta', $form_id, $form );

This filter is located in GFFormDisplay::get_form_meta() in form_display.php.

Since

The form specific version of this filter was added in Gravity Forms 1.9.6.