dhtmlxfom -- populating form with Json data

Hello,

I am using DHTMLXform for a project I am working on. I want to populate a select box with data from a database using Json. Below is my code to construct the form, followed by the code in getContractJson. The select box appears but it is empty. I have echoed out “$items” and the data is there. Thanks for your help!

Cheers,

[code]formData = [{
type: “select”,
position: “label-left”,
label:“Company Name”,
name: “companyname”,
//connector: “getContractXML.php”,
labelWidth: 200,
inputWidth: 80
}, {
type: “calendar”,
dateFormat: “%d-%m-%Y”,
name: “start_date”,
label: “Start Date”,
readonly: true,
value: “25-02-2013”,
enableTime: true,
calendarPosition: “right”
},{
type: “input”,
name: “duration”,
label: “Estimated Lesson Duration (hours)”,
value: “1.5”,
position: “center”
}, {
type: “input”,
name: “perweek”,
label: “Estimated #lessons/week”,
value: “2”
}];
myForm = new dhtmlXForm(“myForm”, formData);

myForm.load("getContractJson.php", "json");[/code]

getContractJson.php :

[code]…
$rs=$conn->execute($query);
$curr=0;
$items = array();
if($rs)
while (!$rs->EOF){
$companyID = strval($rs[‘CompanyID’]);
$companyName = strval($rs[‘CompanyName’]);

$items[$curr] = array(
‘companyid’ => $companyID,
‘companyname’ => $companyName
);

$rs->MoveNext();
$curr=$curr+1;
}
json_encode($items);
//return json_encode($items);

?>
[/code]

Hello
Please, be guided this sample:
dhtmlx.com/docs/products/dht … tions.html
Uncommend this line:

//connector: "getContractXML.php"

and don’t use this:

myForm.load("getContractJson.php", "json");

In your form structure you already have connector: “getContractXML.php”
Some more details about php connector here:
docs.dhtmlx.com/doku.php?id=dhtm … ctor:start

Hello and thank you for your comment. However, I get an error “invalid XML”. My php file generates Json. Can I load Json data and if so, how?

Thank you.

We need direct link to test it.
Or completed demo to reproduce the issue.
docs.dhtmlx.com/doku.php?id=othe … leted_demo