bookmark_bordergform_form_post_get_meta

Description

This filter can be used to manipulate the Form Object, it is executed when the form meta is retrieved. Any changes made to the form object via this filter would be affect form render, validation, submission, and the form in the admin.

When using this filter you wouldn’t need to make the same change using the gform_pre_render, gform_pre_validation, gform_pre_submission_filter, or gform_admin_pre_render filters.

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_6', 'your_function_name' );

Parameters

Examples

Example 1

The following example dynamically populates a checkbox field with a list of published posts

//NOTE: update the '221' to the ID of your form
add_filter( 'gform_form_post_get_meta_221', 'populate_checkbox' );
function populate_checkbox( $form ) {

    foreach( $form['fields'] as &$field )  {

        //NOTE: replace 3 with your checkbox field id
        $field_id = 3;
        if ( $field->id != $field_id ) {
            continue;
        }

        // you can add additional parameters here to alter the posts that are retreieved
        // more info: [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)
        $posts = get_posts( 'numberposts=-1&post_status=publish' );

        $input_id = 1;
        foreach( $posts as $post ) {

            //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
            if ( $input_id % 10 == 0 ) {
                $input_id++;
            }

            $choices[] = array( 'text' => $post->post_title, 'value' => $post->post_title );
            $inputs[] = array( 'label' => $post->post_title, 'id' => "{$field_id}.{$input_id}" );

            $input_id++;
        }

        $field->choices = $choices;
        $field->inputs = $inputs;

    }

    return $form;
}

Placement

This code should be placed in the functions.php file of your active theme.

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.