Now, we will provide loading data to the form. Our form will present details of 2 customers: "Customer 1" and "Customer 2". We'll use a MySQL database "sampledb " and the table "customers " in it as the data source.
We will add 2 buttons: "Customer 1" and "Customer 2" to load details of a specific customer to the form. Initially, we will load details of Customer 1.
To load data we will use the PHP platform and the dhtmlxConnector library, as this is the easiest way to implement the server-side logic for a DHTMLX-based application.
1) Make sure that your MySql, Apache servers are running and you've defined the correct directory to your app for them, otherwise the error "LoadXML" will appear.
2) Make sure that your
'ID' field in the database is set as autoincrement.
"formdata.php" file
<?php
require_once("codebase/connector/form_connector.php");//includes connector file
//connects to the database with the name "sampledb"
$res=new PDO("mysql:dbname=sampledb;host=localhost","user","password");
$conn = new FormConnector($res); //initializes the connector object
$conn->render_table("customers","id","name,address,email");//loads data from db
Make sure that all the includes used within the connector's script don't have any whitespaces beyond the <?php and ?> tags. 'index.html'
myform.load('formdata.php?id=1'); //takes the path to your data feed
As a parameter, the method takes the path to the server-side script. The path must include the id of the loaded record.'index.html'
myform.attachEvent("onButtonClick", function(id){
if (id=='button1'){
myform.load("formdata.php?id=1")//loads data of the 1st customer (id=1)
}
else if (id=='button2'){
myform.load("formdata.php?id=2")//loads data of the 2nd customer (id=2)
}
});