Hello,
I’ve spent most of today trying to get my form to load, and also to get the form to update the database. I’m sure there is something I’m doing wrong, but I’ve looked at the documentation and samples, and can’t figure it out.
Here is the form:
[code]
Constructed form
var dp;
var formData;
var myForm;
function doOnLoad() {
formData = [{
type: “input”,
name: “Title”,
label: “Title”,
value: “”,
width: “750”,
bind: “title”
}, {
type: “input”,
name: “Description”,
label: “Description”,
value: “”,
width: “750”,
bind: “code”
}, {
type: “input”,
name: “Justification”,
label: “Justification”,
value: “”,
width: “750”,
bind: “lvl”
}
];
myForm = new dhtmlXForm("myForm",formData);
myForm.load("myFormConnector.php?code='1008A695'");
dp = new dataProcessor("myFormConnector.php");
dp.setTransactionMode("POST",true)
dp.init(myForm);
}
dhtmlxError.catchError("ALL",function(a,b,data){
//data[0] - request object
alert(data[0].responseText); // - incorrect server side response
//alert(data[0].status);
});
function saveData() {
dp.save();
}
</script>
</head>
<body onload="doOnLoad();">
<div id="myForm"></div>
<input type="button" value="Save data" command="save" onclick="javascript:saveData();">
</div>
</body>
[/code]
Here is the PHP connector:
[code]<?php
require_once(“/dhtmlxSuite/dhtmlxConnector/codebase/db_sqlsrv.php”);
require_once(“/dhtmlxSuite/dhtmlxConnector/codebase/form_connector.php”);
$serverName = "CH-SQL-6\Pentamation_rpt";
$uid=file_get_contents("C:\inetpub\wwwroot_DEV\uid.txt");
$pwd=file_get_contents("C:\inetpub\wwwroot_DEV\pwd.txt");
$connectionInfo = array( "UID"=>$uid, "PWD"=>$pwd, "Database"=>"COF_Objects_Dev", "LoginTimeout"=>15); // <- SS authentication
$res = sqlsrv_connect( $serverName, $connectionInfo); // <- SS authentication
if($res)
{
echo "Connection established.\n";
}
else
{
echo "Connection could not be established.\n";
die( print_r( sqlsrv_errors(), true));
}
$form = new FormConnector($res,"SQLSrv");
$form->render_sql("SELECT title, code, lvl FROM proj_title","code","title, code, lvl","");
/* Close the connection. */
sqlsrv_close($res);
echo “Connection closed.\n”;
?>[/code]
And here are my questions:
-
Do I use the data connector to UPDATE the database table from the form, or can I use just the connector for both SELECT and UPDATE?
-
Do I use one PHP connector file to SELECT and another one to UPDATE the database?
-
How do I tell the form to load a specific record? I tried
myForm.load("myFormConnector.php?code='1008A695'");
where the record ID is ‘1008A695’, but it didn’t work; all fields are empty after form load.
- How do I tell the form to save changes? Clicking on the SAVE button produces a JavaScript error, ‘Object doesn’t support this method’ at
myForm.load("myFormConnector.php?code='1008A695'");
Thank you for your help.