Hi There
I have a problem with populating a select field in a form. The values for the options are comming from a oracle database. I have the following code:
kiesland.xml:
var oTab = this.viewNode;
bb.command.load('haal_landen.php','GET',null,null,null,'', function (oResponse, oElm){
oTab.innerHTML = oResponse.responseText;
});
haal_landen.php:
$zin ="";
include ("./dblogon1.php");
$prodqry="select land_id, land_naam from landen order by 2";
$stmt = OCIParse($con, $prodqry);
OCIExecute($stmt, OCI_DEFAULT);
// check our query
$Error = OCIError($stmt);
if ($Error['code'])
{
print $Error['message'];
exit;
}
while (OCIFetch($stmt))
{
$landid= strtolower(trim(OCIResult($stmt, "LAND_ID")));
$land= OCIResult($stmt, "LAND_NAAM");
$zin .= "$land";
}
OCILogoff($con);
$zin .= "";
header ( "Content-type: text/xml; charset=utf8" );
$zin = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . $zin . "";
echo $zin;
When the html is loaded i get in the debugger messages about xml faults.
When you look at the data in the screen you see at the end .........
But the select is wel fulled. When i stop the debugger (push X) and reload the page then the error does not popup. Another refresh and there is the error again
What is wrong here?
Or is the way i follow here wrong?

xml faults
13 May, 2008 - 18:03 — andysHi richardreen,
Would you like to give us the xml return from php?
Maybe we can have more overview about this case
Andys
How to fill fields in a form with php.
14 May, 2008 - 21:35 — richardreenI will restate my problem because i was searching in this forum for similar problems and did find some but i was not succesfull.
I have a from with a select field:
<option value="....">....</option>
<option value="....">....</option>
</select>
The values for the option fields are stored in a database and i want to get the data from the database and fill the option fields with that data.
I want to use a php-script like this:
echo "<select name=\"land\">";
include ("./dblogon1.php");
$prodqry="select land_id, land_naam from landen order by 2";
$stmt = OCIParse($con, $prodqry);
OCIExecute($stmt, OCI_DEFAULT);
// check our query
$Error = OCIError($stmt);
if ($Error['code'])
{
print $Error['message'];
exit;
}
while (OCIFetch($stmt))
{
$landid= strtolower(trim(OCIResult($stmt, "LAND_ID")));
$land= OCIResult($stmt, "LAND_NAAM");
echo "<option value=\"$landid\">$land</option>";
}
OCILogoff($con);
echo "</select>";
?>
I tried several technics but no succes. The last one i did like this:
<th><label for="land">Land</label></th>
<td><xi:include href="haal_landen.php"></xi:include>
</td></tr>
So there are two issues:
1 How to make the php-code to generate a good filling for the select field.
2 How to include the php-script in the form. (is in xml-style)
Maybe somebody has a similar working example.
php select options
15 May, 2008 - 09:26 — andysHi richardreen,
What is the exact problem you got actually? The problem with the php formulating the select-options or problem with including the php file.
The way you include the php file is correct. Is there any exact error message from our debugger? It will be really helpful to give us the error message returned from the debugger.
Andys
PHP needs to return XML
15 May, 2008 - 10:16 — ghicaOne thing that is certainly wrong with your code is that your PHP script needs to return XML.
You can achieve this by having the following as the first two lines after
<?phpecho '<?xml version="1.0" encoding="UTF-8"?>' ?>
And, of course the content should be proper XML too, which seems ok in your example.
Cheers, Ghica
Debugger info
15 May, 2008 - 19:50 — richardreenI changed the php code and tested in a browser. (loaded php file separately) It says valid xml dokument (or something like that)
But now i get for all items in the select a debugger message
# GENERIC: Unknown element "null#select". Using "null:element" as fallback. select
# GENERIC: Unknown element "null#option". Using "null:element" as fallback. option
# GENERIC: Unknown element "null#option". Using "null:element" as fallback. option
# GENERIC: Unknown element "null#option". Using "null:element" as fallback. option
# GENERIC: Unknown element "null#option". Using "null:element" as fallback. option
etc....
From this i know that the include is working!. The only thing left is now how to solve this error.
What is wrong now?
Include also failing after instructions from Dev.Guide
15 May, 2008 - 20:19 — richardreenAfter that i did read again the Developer Guide and saw that in the definition of the from there must be a declaration for the namebases like:
<table border="0" width="550px">
<tbody>
<tr>.....
So i tried it, did a reload of the page and then the debugger showed the following error:
I did follow the instructions from the guide and the namespace xi was defined and failed totally...why?
You need a namespace in your PHP reply too.
15 May, 2008 - 20:45 — ghicaI forgot to mention this, sorry. But since you are loading into Backbase space, your select needs to have the xhtml namespace included, like this:
<select name="land" xmlns="http://www.w3.org/1999/xhtml">...To be more specific, the root node of your PHP reply needs to specify the necessary namespaces. You would need additional namespaces if you were loading BTL widgets for example.
Cheers, Ghica.
It is working
16 May, 2008 - 08:10 — richardreenIt is working now, only slow.
Thnxs andys and ghica.
Performance
16 May, 2008 - 09:42 — ghicarichardreen,
I am happy that it is working. To improve the speed of your application, you may want to re-think the setup of your page. You are using an xi:include to load the options of the select. From a client perspective, this is static data. You could have retrieved that data from the database -before- you were building the page with the form in it, and send the options together with the form. That would speed up the display of the page.
Backbase will shine when you need to load data dynamically, while your page is already displayed. xi:include is just a convenience that allows you to make your server code more modular.
To load data dynamically, you would use load command, either c:load or bb.command.load(), as a response to an event that occurs on your page.
What would have been nice too, is to use a b:comboBox with filter=true instead of a select. In this way your interface for choosing the countries would be a bit more friendly to your user. Or, if you really want to get fancy and load a limited set of data, while the user narrows down his/her choice, you could use a b:suggestBox with a b:dataSource that is progressively populated from the server. But that is only useful if there are thousands of options.
The dynamics are in the action of the form, but since you did not explain what you were planning to do with the form response, I cannot comment on that.
Cheers, Ghica.