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
- $form Form Object
The current form to be filtered.
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
Use the gform_entry_meta_pre_render_feed_settings
filter instead.
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
As of Gravity Forms 2.9.1 filter is located in GFCommon::gform_admin_pre_render(). It was previously located in the following methods:
- GFNotification::get_notification_ui_settings() in notification.php
- GFEntryDetail::lead_detail_page() in entry_detail.php
- GFEntryDetail::lead_detail_edit() in entry_detail.php
- GFFormDetail::forms_page() in form_detail.php
- GFFormSettings::confirmations_edit_page() in form_settings.php
- GFFormSettings::form_settings_ui() in form_settings.php