Using Gravity Forms ‘gform_admin_pre_render’ PHP action

The gform_admin_pre_render action allows you to modify the Form Object before displaying the entry detail in the Gravity Forms admin interface.

Usage

add_action('gform_admin_pre_render', 'your_custom_function');

Parameters

  • $form (Form Object): The current form to be filtered.

More information

See Gravity Forms Docs: gform_admin_pre_render

Examples

Populate a choice-based field

This example populates a dropdown field with post titles from the “Business” category.

add_action('gform_admin_pre_render', 'populate_dropdown');

function populate_dropdown($form) {
    if ($form['id'] != 5)
        return $form;

    $posts = get_posts('category=Business');
    $items = array();
    $items[] = array('text' => '', "value" => '');

    foreach ($posts as $post)
        $items[] = array('value' => $post->post_title, 'text' => $post->post_title);

    foreach ($form['fields'] as &$field) {
        if ($field->id == 8) {
            $field->choices = $items;
        }
    }

    return $form;
}

Enable entry meta in feed conditional logic

This example enables entry meta, such as quiz score, for use in configuring conditional logic rules on the ActiveCampaign feed.

add_action('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.