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