Check documentation for the latest version 6.0 of dhtmlxSuite Form Specific HowTos DHTMLX Docs

Form Specific HowTos

How can I populate the '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 the client side:

client side:

var formData = [{type: "select", label: "Categories", connector:"selectOptions.php"}];

server side:

<?php 
require_once("../codebase/connector/options_connector.php");
$res=new PDO("mysql:dbname=myDB;host=localhost","root","");
 
$data = new SelectOptionsConnector($res, "MySQL");
$data->render_table("categories","id","valueColumn, labelColumn");
 
?>

For more information on 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 the 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=new PDO("mysql:dbname=myDB;host=localhost","root","");
 
$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 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 the server side and the method load (id) on the client side:

client side

myForm.load('formdata.php?id=1');

where a connector file with the id of loading record must be specified as the parameter.

The values of the record's columns will be used as the values of form's controls.

server side

<?php 
require_once("../codebase/connector/form_connector.php");//includes needed connector 
// connects to the "tasks" database
$res=new PDO("mysql:dbname=tasks;host=localhost","root","");
$conn = new FormConnector($res,"MySQL"); // connector initialization
$conn->render_table("customers","id","name, address, email"); // data configuration 
?>

For more information on this topic, see 'dhtmlxForm.Work with the 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 the client side.

You can call this method, for example, on clicking some button.

myForm.attachEvent("onButtonClick", function(id){
    if (id=='saveButton'){
        myForm.save();
    }
}

For more information on this topic, see 'dhtmlxForm.Work with the Server Side' tutorial.

Back to top