gform_admin_pre_render

Description

This filter is executed before the entry detail is displayed and can be used to manipulate the Form Object prior to rendering the entry.

Usage

Applies to all forms

add_action( 'gform_admin_pre_render', 'pre_render_function' );

Applies to a specific form. In this case, form Id 5

add_action( 'gform_admin_pre_render_5', 'pre_render_function' );

Parameters

Examples

1. Populate a choice based field.

This example dynamically populates a drop down field with posts that are in the Business category.

add_filter( 'gform_admin_pre_render', 'populate_dropdown' );
function populate_dropdown( $form ) {

    // Only populating the dropdown for form ID 5
    if ( $form['id'] != 5 ) {
        return $form;
    }

    // Reading posts for the "Business" category
    $posts = get_posts( array( 'category_name' => 'Business' ) );

    // Creating dropdown item array
    $items = array();

    // Adding initial blank value
    $items[] = array( 'text' => '', 'value' => '' );

    // Adding post titles to the items array
    foreach ( $posts as $post ) {
        $items[] = array( 'value' => $post->post_title, 'text' => $post->post_title );
    }

    // Adding items to field ID 8. Replace 8 with your actual field ID.
    // You can get the field ID by looking at the input name in the markup.
    foreach ( $form['fields'] as &$field ) {
        if ( $field->id == 8 ) {
            $field->choices = $items;
        }
    }

    return $form;
}

2. Enable entry meta in feed conditional logic

This example shows how entry meta, such as the quiz score, can be enabled for use when configuring conditional logic rules on the ActiveCampaign feed.

add_filter( 'gform_admin_pre_render', function ( $form ) {
    if ( rgget( 'page' ) == 'gf_edit_forms' && rgget( 'view' ) == 'settings' && rgget( 'subview' ) == 'gravityformsactivecampaign' ) {
        echo "<script type='text/javascript'>var entry_meta = " . json_encode( GFFormsModel::get_entry_meta( $form['id'] ) ) . ';</script>';
    }

    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

This filter is located in the following methods:

  • GFEntryDetail::lead_detail_page() in entry_detail.php
  • GFEntryDetail::lead_detail_edit() in entry_detail.php
  • GFFormDetail::forms_page() in form_detail.php
  • GFFormSettings::form_settings_ui() in form_settings.php
  • GFFormSettings::confirmations_edit_page() in form_settings.php
  • GFNotification::get_notification_ui_settings() in notification.php