If you create a simple form with a single dropdown and want to populate it with a database table that contains all 50 states, Copy and paste the code below, replace the Form ID number and tables. It will work. Hope solutions are allowed here.
add_filter("gform_pre_render_5", populate_dropdown); //5 is the GF Form ID
add_filter("gform_admin_pre_render_5", populate_dropdown);
function populate_dropdown($form){
global $wpdb; //Accessing WP Database (non-WP Table) use code below.
$results = $wpdb->get_results("SELECT btc_state_short from btc_state_list");
$choices = array();
$choices[] = array("text" => "Select a State", "value" => ""); //adding a array option with no value, this will make the user select and option.
foreach ($results as $result) {
$choices[] = array("text" => $result->btc_state_short, "value" => $result->btc_state_short);
}
foreach($form["fields"] as &$field){
if($field["id"] == 1){
$field["choices"] = $choices;
}
}
return $form;
}