Combo and connectors

Hi, I’m beginners of DHTMLX suite.
I’m trying to modify the website example “Contact Manager” for a new simple application.
The problem is that when add a new record: the popup-form to insert data must have a combobox which retrieve data from a database.

The script code is:


		offerteToolbar.attachEvent("onclick",function(id){
			if(id=="addOfferta"){
				//open popup window
				var popupWindow = dhxLayout.dhxWins.createWindow("newoff_win", 0, 0, 220, 250);
				popupWindow.center();
				popupWindow.setText("Nuova Offerta");
				//add form
				var newOffForm = popupWindow.attachForm();
				newOffForm.loadStruct("xml/offertaform.xml");
				var dpfs = new dataProcessor("xml/offerta_dett.php");
				dpfs.init(newOffForm);
                                ...
			}

and offertaform.xml is:

<?xml version="1.0"?>
<items>
<item type="label" label="Codice NAV"/>
<item type="select" name="NAVcode" bind="NAVcode" label="Codice Offerta NAV"></item>
<item type="label" label="Descrizione"/>
<item type="input" name="descrizione" bind="descrizione" label="Descrizione Offerta"/>
<item type="label" label=""/>
<item type="button" command="save" value="Submit"/>
</items>

Now I need to populate the combo “NAVcode” with value selected from a table (f.ex. table1) which have 2 columns (f.ex. id, descr).

I’ve searched in doku/example/forum but didn’t found an answer.
May you help me?

Hello,

You may set connector property with path to the server-side script that generates options. Please see the sample:
dhtmlxForm/samples/05_data/05_options.html

Hello Alexandra,
I’ve found the example indicated and I’ve tried, but it doesn’t work.

The connector’s script that I using (the analog php/options.php script in the example) is:

<?php
require("codebase/connector/form_connector.php");
$res=mysql_connect("localhost","user","pwd");
mysql_select_db("myDb");

$options = new SelectOptionsConnector($res);
$options->enable_log("log/combo.log"); 
$options->render_sql("SELECT id, descr FROM myTable","","id,descr");
?>

But it return me an error:

Error Type: LoadXML
Description: Incorrect XML

that’s he same result that I’m receiving from the dhtmlxForm/samples/05_data/05_options.html example page.
May you give me a correct template of the php-connector script?

Thanks.
Andrea

But it return me an error

check log/combo.log file. There you find error information.

You need to use ‘codebase/connector/options_connector.php’ instead of “codebase/connector/form_connector.php”

Alexandra, no files log/combo.log is generated.
Although I’ve changed in options_connector.php, it doesn’t work correctly.

Other suggest?

Andrea.

Here is the same sample on our website and it works correctly:
dhtmlx.com/docs/products/dht … tions.html

Hi Alexandra.
I’ve seen that the example now works correctly. Thanks.

May you give an example of “php/options.php” script? Because my script, however It seems like a documentation template, doesn’t work.

Tnx, Andrea.

options.php:

<?php require_once('../../common/config.php'); require_once('../../../codebase/connector/options_connector.php'); $options = new SelectOptionsConnector($conn); //$options->enable_log("log.txt"); $options->render_sql("SELECT Id, Package FROM packages_plain WHERE Id < 50","","Id,Package"); ?>

Alexandra, I’ve tried the example that you’ve indicate and it works fine.
When I load the structure of the combo from an xml file doesn’t work.
It seems that didn’t use the php connector file: is even the “connector” property to use in this case? Is the same in every load mode HTML/JSON/XML ?

<?xml version="1.0"?>
<items>
<item type="label" label="Codice NAV"/>
<item type="select" name="NAVcode" bind="NAVcode" label="Codice Offerta NAV" connector="php/options.php"></item>
<item type="label" label="Descrizione"/>
<item type="input" name="descrizione" bind="descrizione" label="Descrizione Offerta"/>
<item type="label" label=""/>
<item type="button" command="save" value="Submit"/>
</items>

try to use attached file instead of the original. It’ll resolve the problem
dhtmlxform.zip (13.8 KB)

Alexandra, I beginning to feel myself stupid.
I’ve copy your file attach, but it’s the same.

The situation is:

A form-file, with a combo/select:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

    <!-- dhtmlx.css contains styles definitions for all included components -->
    <link rel="stylesheet" type="text/css" href="codebase/dhtmlx.css">

	<script src="codebase/dhtmlxcommon.js"></script>
	<script src="codebase/dhtmlxform.js"></script>
		
	<script type="text/javascript">

	var formGen;
	function doOnLoad() {
		formGen= new dhtmlXForm("listObj");
		formGen.loadStruct("offertaform.xml");
	
	}
	</script>
</head>
<body onload="doOnLoad()">
	<div id="listObj" style="position: relative; width: 250px;"></div>
<body>
</body>
</html>

A file xml with the structure (offertaform.xml):

<?xml version="1.0"?>
<items>
	<item type="label" label="Codice NAV"/>
	<item type="select" name="NAVcode" bind="NAVcode" label="Codice Offerta NAV" connector="select_offerte_NAV.php" ></item>
	<item type="label" label="Descrizione"/>
	<item type="input" name="descrizione" bind="descrizione" label="Descrizione Offerta"/>
	<item type="label" label=""/>
	<item type="button" command="save" value="Submit"/>
</items>

And a connector php file (select_offerte_NAV.php):

<?php
require("codebase/connector/options_connector.php");
$res=mysql_connect("localhost","andreacova","gsx750r:)");
mysql_select_db("inbelfor");

$options = new SelectOptionsConnector($res);
$options->enable_log("/var/www/html/inbelfor/offerte/log/log1.txt");
$options->render_sql("SELECT id, descr FROM cantieri where id < 5000","","id,descr");
?>

Very simple, as my errors - I think - but I haven’t the solution.

Andrea.

Sorry, we have found one more bug in form. I’ve attached the sample with fixed dhtmlxform.js
form.zip (55.3 KB)

Very well, Alexandra.
It work!!!

I’m, probably stupid, but no so much! :wink:

Thanks you for the patient work.
Bye.

Hi, I’m experiencing exactly the same issue …

Is this issue will be solved in dhtmlx 2.7 ?

There is not 2.7 version. You may find the fixed dhtmlxform.js in the sample attached to this topic.