Problem populating form select options from DB connector.

Hi Folks,

I’m just getting my feet wet with dhtmlx, and I’m having some trouble populating a form’s select box options from my database via the form connector. This seems very basic, and I think perhaps I’ve missed something.

Upon page load, in one of the cells, a blank form is loaded, which contains only a single select box.

ksForm = eveLayout.cells(“b”).attachForm();
ksForm.loadStruct(“include/xml/selectedks.xml”);

The form looks like this:

<?xml version="1.0" encoding="UTF-8"?>

I have an event in the grid on this page that’s supposed to populate the options of the select box from the database:

hostGrid.attachEvent(“onRowSelect”, function(rID){
ksForm.load(“include/php/ksoptions.php?id=”+rID);
})

Here’s the guts of that …

require("…/connector/form_connector.php");
$dbh = mysql_connect(“localhost”,“root”,“xxxxxx”);
mysql_select_db(“xxx”);

$hostid = $_REQUEST[‘id’];

$formConn = new FormConnector($dbh,“MySQL”);
$optsConn = new OptionsConnector($dbh);
$optsSQL = "select kickstarts.id as value, kickstarts.name as label from kickstarts ".
"inner join distro_kickstarts on distro_kickstarts.kickstartid = kickstarts.id ".
"inner join distros on distros.id = distro_kickstarts.distroid ".
“inner join hosts on hosts.distroid = distros.id where hosts.id = $hostid”;
$optsConn->render_sql($optsSQL, “”, “value,label”);

$formConn->set_options(“id”, $optsConn);
$formConn->render_table(“kickstarts”,“id”,“id”);

… now, thanks to the firebug plugin in Chrome, I can see what data is being returned:

<?xml version='1.0' encoding='utf-8' ?>

These are the options that I expect… but… these options don’t get populated in the select box in the form.

What might I be missing with how this works?

Thanks!

Hi,

FormConnector and OptionsConnector can not be used at once.

FormConnector generates the xml with form values. OptionsConnector returns xml with select options.

To define path to xml with options (or php script that generates it) you can use connector attribute in “select” config:
dhtmlxForm/samples/06_data/05_options.html

path to xml with form data is defined in load() method:

dhtmlxForm/samples/06_data/01_load.html

Thanks for the info… that helped me reason this out.

One last thing I’m running into is a method for choosing the “selected” option. What the queries in my original post were attempting to do was create a list of all options available to the host, then set the “selected” option to the current value in the database.

I was able to do something similar for the host grid… but I can’t seem to find the correct magic for this in my form. Could you pass me another clue?

Thanks!

Hello,

the option will be selected after data loading - the option that correspond item value will be seleced. Or you can set combo value using setItemValue method.

SelectOptionsConnector doesn’t allow to define “selected” attribute for an option.