PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Dropdown of users

  1. RobertDrake
    Member

    I'm setting up something like an intranet and I'm hoping to have a gravity form that could be used similar to a contact user form. I'm stuck on how to create a dropdown that is pre-filled in with registered users (specifically, subscriber users.) Is this functionality possible?

    Thank you

    Posted 13 years ago on Friday September 24, 2010 | Permalink
  2. Yes this is possible, however you would have to know PHP and WordPress development and then a hook to dynamically change the drop down. How advanced are your PHP skills?

    Posted 13 years ago on Friday September 24, 2010 | Permalink
  3. RobertDrake
    Member

    Better than none, but worse than perfect? I'm familiar with wordpress hooks (I've done plugin development before, but nothing especially credential impressive.)

    I've been looking at: http://www.dynamicguru.com/php/how-to-list-all-registered-users-on-your-wordpress-site/ which has

    $all_users_id = $wpdb->get_col( $wpdb->prepare(
            "SELECT $wpdb->users.ID FROM $wpdb->users ORDER BY %s ASC"
            , $sort ));

    which seems to be in the direction of what I might need?

    Posted 13 years ago on Friday September 24, 2010 | Permalink
  4. See this thread, there is a lot of discussion on this thread regarding pre-populating a drop down dynamically...

    http://forum.gravityhelp.com/topic/automatically-populate-a-dropdown-with-post-titles

    Posted 13 years ago on Friday September 24, 2010 | Permalink
  5. RobertDrake
    Member

    I've pretty much got it working. For anyone trying to do something similar:

    add_filter("gform_pre_render_1", populate_dropdown);
    
    function populate_dropdown($form){
    
    global $wpdb;
    $wp_user_search = $wpdb->get_results("SELECT ID, display_name FROM $wpdb->users ORDER BY ID");
    
    //Creating drop down item array.
    $items = array();
    
    //Adding initial blank value.
    $items[] = array("text" => "", "value" => "");
    
     //Adding post titles to the items array
    foreach ( $wp_user_search as $userid )
    	$items[] = array("value" => $userid->display_name, "text" => $userid->display_name);
    
     //Adding items to field id 8. field_1_2
        foreach($form["fields"] as &$field)
    
            if($field["id"] == 3){
                $field["type"] = "select";
                $field["choices"] = $items;
    
            }
    
        return $form;
    }

    One thing that's really cool - on the text field I set the default value to be the currently logged in user (me). When I repopulate the field is still sets my user to be the default value (aka it finds me in the list.)

    Very cool stuff and excellent support. Thank you.

    Posted 13 years ago on Saturday September 25, 2010 | Permalink
  6. No problem, glad you got it working... keep watching as we will be launching an expanded documentation area soon that includes more in depth developer documentation for the available hooks and filters. The content itself is done we just have to integrate the WikiMedia install into the support site and we are currently busy with Gravity Forms development which comes first.

    Posted 13 years ago on Saturday September 25, 2010 | Permalink