# Fill Gravity Forms Choices With Team Members

> Fills a Gravity Forms drop-down or radio field with the names of users in a role, such as staff or agents, so visitors can choose who they want to contact.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: gravity-forms, dynamic, users
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/gf-choices-from-users/

## Code

```php
$wpide_gf_users = function ( $form ) {
    foreach ( $form['fields'] as $field ) {
        if ( ! in_array( $field->type, array( 'select', 'radio' ), true ) || ! preg_match( '/\bpopulate-role-([a-z0-9_-]+)\b/', (string) $field->cssClass, $m ) ) {
            continue;
        }

        $users = get_users( array( 'role' => $m[1], 'orderby' => 'display_name', 'fields' => array( 'ID', 'display_name' ), 'number' => 200 ) );

        $field->choices = array_map( function ( $user ) {
            return array( 'text' => $user->display_name, 'value' => (string) $user->ID );
        }, $users );
    }

    return $form;
};

add_filter( 'gform_pre_render', $wpide_gf_users );
add_filter( 'gform_pre_validation', $wpide_gf_users );
add_filter( 'gform_pre_submission_filter', $wpide_gf_users );
add_filter( 'gform_admin_pre_render', $wpide_gf_users );
```

## Notes

Give the field the CSS class populate-role-<role> (for example populate-role-editor); values are user IDs, so pair it with a routing snippet if you email the chosen person.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Fill Gravity Forms Choices With Team Members" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
