Component-specific how-tos (form)
How can I populate 'select' item with data from db?
To define options of the select item you should use SelectOptionsConnector on the server-side and specify the connector parameter for the appropriate item on client-side:
client-side:
var formData = [{type: "select", label: "Categories", connector:"selectOptions.php"}];
server-side:
<?php require_once("../codebase/connector/options_connector.php"); $res=mysql_connect("localhost","root",""); mysql_select_db("myDB"); $data = new SelectOptionsConnector($res, "MySQL"); $data->render_table("categories","id","valueColumn, labelColumn"); ?>
For more information of this topic, see 'SelectOptionsConnector' article.
How can I populate 'combo' item with data from db?
To define options of the 'combo' item you should use ComboConnector on the server-side and specify the connector parameter for the appropriate item on client-side:
client-side:
var formData = [{type: "combo", name: "myCombo", label: "Select type", connector:"comboOptions.php"}];
server-side:
<?php require_once("../codebase/connector/combo_connector.php"); $res=mysql_connect("localhost","root",""); mysql_select_db("myDB"); $data = new ComboConnector($res, "MySQL"); $data->render_table("categories","id","valueColumn, labelColumn"); ?>
- Names of the fields can have aliases (value or label) to identify the appropriate attribute.
$data->render_sql("SELECT *, CONCAT(FirstName, LastName) as label FROM table1","id","id,FirstName(label)");
Note, in the filtering mode a combo filters data by the “label” field.
How can I load data from db?
To load data to a form you should use FormConnector on server-side and the method load (id) on client_side:
client-side
myForm.load('formdata.php?id=1');
where as the parameter must be specified a connector file with the id of loading record.
Values of record's columns will be used as values of form's controls.
server-side
<?php require_once("../codebase/connector/form_connector.php");// includes the appropriate connector $res=mysql_connect("localhost","root","");//connects to a server that contains the desired DB mysql_select_db("tasks");// connects to the DB. 'tasks' is the name of our DB $conn = new FormConnector($res,"MySQL");// connector initialization $conn->render_table("customers","id","name, address, email");// data configuration ?>
For more information of this topic, see 'dhtmlxForm:easy dealing with server-side' tutorial.
How can I save changes made in a form to db?
To save form changes to DB, you should use the method save() on client-side.
You can call this method, for example, on clicks of some button.
myForm.attachEvent("onButtonClick", function(id){ if (id=='saveButton'){ myForm.save(); } }
For more information of this topic, see 'dhtmlxForm:easy dealing with server-side' tutorial.