dhtmlxconnector:formconnector_usage [DHX documentation]

PHP Connector DHTMLX

dhtmlxConnector for form

index.html

<!DOCTYPE HTML>
<html>
<head>
	<link rel="STYLESHEET" type="text/css" href="../codebase/dhtmlx.css">
	<script  src="../codebase/dhtmlx.js"></script>	
	<script type="text/javascript" src="../codebase/connector.js"></script>
	<div id="box" style="width:250px; height:160px; background-color:white;"></div>
</head>
 
<body>
<script type="text/javascript">
//---form configuration. Defining controls
	formData = [
				{type: "block", list:[
				{type: "fieldset",  name: "mydata", label: "Customer details", width:235, list:[
					{type: "input", name:"name", label: "Name",  labelWidth:50, inputWidth:130},
					{type: "input", name:"address", label: "Address",  labelWidth:50,  inputWidth:130},
					{type: "input", name:"email", label: "Email",  labelWidth:50,  inputWidth:130},
					{type: "button", name:"save", offsetTop:10,  value:"Submit"}
                ]}]},
				{type: "block", list:[
				{type: "button", name:"button1", value:"Customer 1", offsetTop:10,width:80},
				{type:"newcolumn"},
				{type: "button", name:"button2", value:"Customer 2", offsetTop:10,width:80}]}
	];
//---form initialization
	var myForm = new dhtmlXForm("box",formData);//object constructor
//---loading data from db. 
        myForm.load('formdata.php?id=1');// as the parameter is a connector file with the id of loading record
//---dataProcessor initialization	
	var mydp = new dataProcessor ("formdata.php");// object constructor. Here you should specify a connector file
	mydp.init(myForm);// initializes dataProcessor. As the parameter you should specify your grid
 
	myForm.attachEvent("onButtonClick", function(id){
			if (id=='button1'){//
				myForm.load('formdata.php?id=1')// loads data of the first customer. The record with the id=1
			}
			else if (id=='button2'){
				myForm.load('formdata.php?id=2')// loads data of the first customer. The record with the id=2
			}
			else if (id=='save'){
				myForm.save();// saves data to db
			}
    });
</script>
</body>
</html>

formdata.php

<?php 
  require_once("../codebase/connector/form_connector.php");
  $res=mysql_connect("localhost","root","");
  mysql_select_db("tasks");
  $conn = new FormConnector($res,"MySQL");
  $conn->render_table("customers","id","name, address, email");
?>