I am trying to populate a drop down list of supplier names with a WordPress plugin "Ninja Forms" using a query to a external database connection and custom code in functions.php.
The drop down list on the form appears to be populating with the correct quantity of results (i.e. 800+ items) but instead showing [object Object] instead of the suppliers name.
The code below is where I got up to, any support on adding the queried supplier name (SUP_Name) instead of [object Object] would be of great use.
add_filter('ninja_forms_render_options','my_pre_population_callback', 10, 2);
function my_pre_population_callback($options, $settings) {
if( $settings['key'] == 'supplier_list' ) {
$connection = mysqli_connect( "IP:port", "username", "password", "db" );
if (!$connection) { die('Not connected : ' . mysqli_error());}
$db_selected = mysqli_select_db($connection,"db");
if (!$db_selected) {
die ('Can\'t use db : ' . mysqli_error());
}
$query = "SELECT SUP_Name FROM db.sup_supplier";
$results = mysqli_query($connection,$query);
if (!$results) {
die('Invalid query: ' . mysqli_error());
}
$options = array();
$options[] = array("label" => "Select the supplier", "value" => "");
foreach ($results as $result) {
$options[] = array("label" => $result, "value" => $result);
}
wp_reset_postdata();
}
return $options;
mysqli_close($con);
}
Thanks in advance