XForms for Managing Forms-Based Data
Use XForms as an elegant alternative to JavaScript
and Java code for managing data entry
by Anthony Tomasic
December 2002 Issue
The World Wide Web Consortium (W3C)'s draft XForms standard defines a set of XML elements that expand vastly the power of data-entry devices, such as browsers, to capture and validate forms-based data. The XForms Working Group has focused on device independence, data validation, and improved internationalization support to give you a new, elegant, and powerful way to code data-entry systems. By centralizing form behavior and data validation into a single location, XForms eliminate the hassle of browser scripting, the associated quagmire of multiple browser-language versions, and the mind-numbing coding of data-validation checks.
You can leverage your knowledge of the existing W3C standards XForms builds on XML, XHTML, Cascading Style Sheets (CSS), XML Schema, XPath, and XML eventsfor a lower XForms learning curve. XForms' features help you spend more time on creative, application-specific work and less time on routine infrastructure.
We'll walk through the details of a typical XForms application that accepts requests from users as part of an e-commerce Web site. A traditional implementation of this system would consist of four pieces. First, Java Server Pages (JSP) present a form, and, second, JavaScript client code validates some of the data entry. Data that users enter on a form goes to a server by HTTP POST, and the result is in Java. If data-entry errors are detected by the server-side validation codethe third componentthe system delivers another form (containing the partially valid data the user entered on the previous form) to the user. Otherwise, the result of data entry is transformed into the fourth elementan XML documentand sent on for the next processing step. Web designers and developers might write a thousand lines of JSP, JavaScript, and Java code for even a simple form.
An XForms-based implementation of the same system consists of three parts. The first is a set of XForms documents the Web designers and developers write. The second is a shared XML schema data model a developer or XML administrator defines. The third partan XForms standard engineinterprets the XForms documents and XML schema.
Each XForms document handles all four aspects of the traditional implementation. The documents reference the shared XML schema, designed explicitly for data entry, that provides explicit support for data validation. A user browser generates an HTTP request for an XForms document; the XForms engine manages the interaction with the user according to the rules defined in the XForms document; the XForms engine validates data entry; and valid data-entry results are delivered to the server as XML documents, ready for the next step in processing. This system requires far less time and labor to construct than the traditional implementation, and it's easier to modify.
Fill Out the Form
In our example, users access a form both to sign up multiple participants in a workshop and conference and to provide additional information such as the participants' company addresses. The full XForms document describes the form. For this discussion I've stripped out most of the HTML style information to concentrate on the XForms material. Both of these listings conform to the January 18, 2002 draft XForms 1.0 standard. (Although the standard is relatively stable, you should expect some changes before the final version arrives.)
Back to top
|