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 drop down for form id 5
    if ( $form['id'] != 5 )
       return $form;

    //Reading posts for "Business" category;
    $posts = get_posts( 'category=Business' );

    //Creating drop down 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 should be placed in the functions.php file of your active theme.

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