Jump to content

Connection To Database From Xforms


ther

Recommended Posts

I understand that php can be used to gain access to a database (e.g. postgresql), but I would like to know if it possible to submit and retrieve data without a scripting language, using xforms as a 'client' to connect to the database.Thanks.xformsatconference.jabber.org

Link to comment
Share on other sites

If both the client and server support it... sure.The problem is no database server supports XML as input on login. Many support it as an actual datatype to insert into the DB, but that's only after you login with an SQL client. The kind of SQL client that languages like PHP have, not an HTTP client. Browsers don't have any kind of DB client capabilities.Also, on the client (browser) side. Even browsers supporting XForms (and there are too few of those) can't send it as a data to a database. XForms provides to way to connect to traditional RDBMS systems. It only gives you the ability to send the data to a certain URL via HTTP with the generated XML file as the body of the HTTP request.So, the short answer to your question is "No".If you want to get the most of XForms, create a nice form that validates its XML with an XML Schema. Send the data to a server side page like a PHP one, validate the XForm instance against the same schema you validated against on the client (you do a second validation for security reasons; using a single schema is one more extra with using XForms; traditionally you'd do validation with JavaScript plus PHP), and then do whatever you want with the XML.

Link to comment
Share on other sites

>The problem is no database server supports XML as input on login. Many support it as an actual datatype to insert into the DB, but that's only after you login with an SQL client. The kind of SQL client that languages like PHP have, not an HTTP client. Browsers don't have any kind of DB client capabilities.Does this mean that to sign in to the database from a web browser, would require the creation of a php code within the xhtml page?>Also, on the client (browser) side. Even browsers supporting XForms (and there are too few of those) can't send it as a data to a database. XForms provides to way to connect to traditional RDBMS systems. It only gives you the ability to send the data to a certain URL via HTTP with the generated XML file as the body of the HTTP request.So far I have tried to use opera to view an xform element within an xhtml page. I could create a text box for the user name, but have not yet understood how to use the 'secret' element for the password submission.>If you want to get the most of XForms, create a nice form that validates its XML with an XML Schema. Send the data to a server side page like a PHP one, validate the XForm instance against the same schema you validated against on the client (you do a second validation for security reasons; using a single schema is one more extra with using XForms; traditionally you'd do validation with JavaScript plus PHP), and then do whatever you want with the XML.Yes. My first test is to create a php page and learn how to connect to the database via php. The test environment will be apache as the web server, with the xforms, php, apache and postgresql parts all one a local machine.Thanks. What about the idea of using xslt to convert the xforms data into a csv file? Could the database be configured to import this file automatically and return the relevant response (e.g. confirm successful connection to database)?

Link to comment
Share on other sites

Does this mean that to sign in to the database from a web browser, would require the creation of a php code within the xhtml page?
Not nesesarily. Any code that could estabilish a database connection would also work. However, note that PHP doesn't (currently...) run inside a browser. It runs on the HTTP server. And even though PHP is on the HTTP server, it is also an SQL client. Your browser is NOT an SQL client. It is an HTTP client. In order to make a browser connect directly to a database, you need to give it some kind of an SQL client capability. You can only do that with a plug-in (think something like "Flash" or "Silverlight"). I don't know of any plug-in for connecting to a PostgreSQL database. You'll have to somehow write your own if you REALLY want that. If you're so eager, you'll have to write it up in C(++) yourself. Do you really want to go THAT far, 'cause I sure wouldn't?
So far I have tried to use opera to view an xform element within an xhtml page. I could create a text box for the user name, but have not yet understood how to use the 'secret' element for the password submission.
Wait... does Opera have any XForms support? As far as I know, no. The fact that you get a text box may be due to a kind of a browser quirk (for the sake of parsing HTML tag soup). The only desktop browser I know have any kind of XForms support is Firefox, with its XForms extension.
Thanks. What about the idea of using xslt to convert the xforms data into a csv file? Could the database be configured to import this file automatically and return the relevant response (e.g. confirm successful connection to database)?
It might be more wise to transform the XML into an actual SQL query that you can then run directly on the databse. I don't know how/if PostgreSQL can parse CSV files.
Link to comment
Share on other sites

  • 2 weeks later...

Thank you for your very clear explanationI am thinking about the following systemApache as the web serverPostgresql as the database(GNU/)LinuxXforms of Openoffice to act as the front-end.I suppose this could be shortened to a mnemonic such as APLEX :)Anyway I have read about the concept of connecting to postgresql using xml via Zwartberg (http://www.zwartberg.com/cave.html). I am seeking to be able to perform the following task:1. Create an xform2. Connect to database by submitting the xform the web server3. Submit data in the xform to the database via the web server4. The database processes the data and returns the result5. The web server converts and sends the database result into a format to be viewed in word processor or web browserI am at stage 2 :) I can create a simple xform with a sign-in and password text boxes, but I do not know how to send this to the web server and then the database. Any advice please?

Link to comment
Share on other sites

I suggest you read W3C's XForms for HTML authors tutorial, in case you haven't already. From the very first example, you can see how you can specify the URL of a page that will accept the form, and handle it.Exactly how do you process the form depends on the actual language you'd use, and sometimes may depend on the XForms processor on the client. Some implementations store the XML in a predefined $_POST variable, while others use the whole response body (as per the XForms spec).If it's a $_POST variable, check out the documentation of the implementation to see the name of the variable it uses. If it's a "standard" implementation... check out the $HTTP_RAW_POST_DATA variable or use file_get_contents('php://input'). For details, see PHP's manual on dealing with XForms.

Link to comment
Share on other sites

Unfortunatly, you still can't avoid using a server side scripting language. Currently, W3C is creating XProc, which has the potential to do exactly what you want, but it's still a draft, and even if it wasn't - there aren't yet implementations that can be seamlessly integrated with Apache or PHP for that matter. There's currently only a JAVA implementation for use within JAVA programs, but that still means you need to actually write JAVA to use it.

What do you mean by 'actual language'?
The server side scripting language. Dealing with XForms is done one way with PHP, and in another way with ASP.NET for example.
Does 'whole response body' mean the 'post' attribute of the element 'submission'?
Sorry. My bad. I meant "whole request body". When you press the submit button on any form (be it an XForm or an HTML form), your brower generates an HTTP request, which it then sends to the server. The server then returns a response, which your browser displays.In the case of a normal HTML form, the browser will generate a set of name-value pairs in the body (each name corresponding to an HTML form element's name, and each value being what the user placed on that field), which PHP may then refer to by accessing the $_POST array.In the case of an XForm, the browser should generate an XML document in the body (matching the described model), which PHP can't refer to by accessing the $_POST array, but may refer to by using file_get_contents('php://input').Some XForms clients (browser plug-ins or JavaScript libraries) trick the browser into placing the XML document as the value of a name-value pair, as per the way HTML forms do it. In this case, you need to know what kind of name does this client uses in that name-value pair. You can find that out by checking the documentation of that XForms client.
Link to comment
Share on other sites

>Unfortunatly, you still can't avoid using a server side scripting language.But the cave system proposed by Zwartberg does not show any script, or am I wrong?
What's that system? Link or something please?Server side scripting languages are not visible in the browser, so if you don't see it doesn't mean there isn't one.
Link to comment
Share on other sites

It seems they're simply using another kind of a server scripting language that instead of using a construct like PHP's "<?php", instead uses special HTML comments.As you can see in the bottom of the "Surf" page, you need to install the Karoo project, and the Surf application. I can't really help you with that though. Just read the documentation to which there are links and... good luck with it.BTW, Karoo appears to be a separate web server, so instead of integrating with Apache, you'd actually have to integrate everything with Karoo instead.

Link to comment
Share on other sites

Thank you for your interpretation into a language I can understand. So now I have to decide on php or karoo...decisions decisions:)
I'd suggest using Apache and PHP, simply because you'll find more people familiar with it to help you with other issues that may arise with it. And not just me, and not just this forum - I mean globally.Also, even though PHP isn't a markup language, it's still relatively easy to learn. Try it.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...