Abstract
The XForms specification [XForms 1.0]represents a way of looking beyond Web forms, to business applications and interactive Web Services, where a human interface meshes with machine-processed XML. This paper provides a quick reference to the major components of the W3C XForms Recommendation.
Keywords
Table of Contents
It's hard to believe that HTML forms have been with us for over a decade. This technology has been the workhorse of web shopping, auctions, searches, polls, and interactive design—but it has limitations.
All data in HTML forms are essentially treated like strings. Common validations such as dates, times, email addresses, postal codes, etc. are not expressible as markup.
Data submitted from HTML forms consist solely of flat name/value pairs. More richly structured data, such as XML, isn't possible. Working with XML data sources, as input or output, requires additional layers of software on the server.
Every form control has different operational parameters for providing initial data. A few examples:
| Form control | Processing for initial data |
|---|---|
| <input type="text" value="***"> | Insert value attribute |
| <textarea>***</textarea> | Insert text content |
| <select><option selected>... | Insert selected attribute at proper location (or locations) |
Table 1.
In each case, the initial data must be specified inline with the rest of the form. In workflow/routing scenarios, where the results of one form are directed to another form, this design requires either dynamic document assembly or sophisticated search/replace functions on the server. This kind of IO-intensive processing puts a bottleneck on even moderate volume form processing.
Even fundamental concepts, such as ensuring a title is structurally connected to a form control, aren't mandated in HTML forms. As a result, a generation of developers has become dependent on tables and other tricks that obscure the structure of the form at the markup level. This makes life more difficult for alternate rendering technologies, including voice browsers.
The common application/x-www-form-urlencoded format for submitted data is poorly defined for characters outside the US ASCII range. As a result, form submission is often encoded with incompatible or proprietary schemes.
HTML form controls are limited and even inappropriate in some contexts found on small devices. For example, an <input type="radio"> form control is tied to a specific representation, which might not make sense on a small device.
"XForms 1.0" is a W3C Recommendation that addresses many shortcomings of classic HTML forms ([XForms 1.0]). XForms is not a freestanding document type, but rather provides a description of markup and processing for integration into other markup languages, such as XHTML 2.0 and SVG.
XForms markup always lives inside another document, called the containing document. Within the containing document, in separate locations, are the parts that describe the form operation and presentation.
The core form definition is called the XForms Model, which contains or links to the initial XML form data, called instance data.
The user interface components are called form controls, which attach to the XForms Model through bindings. The overall application that processes XForms is called an XForms Processor.
XForms can make use of XML Schema datatype information, when available, as well as support rich validations expressed with declarative XPath.
Data submitted from XForms can be formatted as XML that conforms to any DTD or Schema, or simply well-formed. Legacy submission formats from classic HTML forms are also supported.
Initial form data can be specified from a separate XML document. Every form control has an identical interface to the form instance data. Thus, the results of one form can be easily directed into another form.
Designed from the ground up for accessibility, XForms supports and encourages form designers to follow best practices to achieve accessible design.
The combination of XML and Unicode enables consistent treatment of ASCII-excluded characters in form data or user interface. XForms have built-in conversion support for different representations of decimal numbers, dates, and times.
Different conformance profiles, called “XForms Full” and “XForms Basic” enable the deployment of forms across devices from powerful workstation computers to tiny phones and appliances.
Historically, classic HTML forms have been authored with JavaScript on the client side, and a completely separate server application to accept and double-check the data. The advent of XForms, however, permits a single XForms Model to provide both client-side processing as well as server-side.
The XForms Model is suitable for use with a variety of front-ends, beyond XHTML, including voice-specific markup, as well as various server architectures.
<model schema="/schemas/instance.xsd"> <instance src="/cgi-bin/get-instance"/> <submission action="/cgi-bin/form-submit"/> </model>
Form data is both obtained and send back as XML. A reference to XML Schema can provide additional metadata, at the option of the XForms engine.
Figure 1. Example of an XForms Model
Largely, the XForms 1.0 specification consists of concrete definitions of existing common practice in forms authoring.
Form controls defined in XForms are similar to those defined in classic HTML forms, though better generalized and less specific to a particular hard-coded implementation choice:
| XForms form control | Classic HTML Forms equivalent |
|---|---|
| <input> | <input type="text"> |
| <secret> | <input type="password"> |
| <textarea> | <textarea> |
| <output> | No equivalent |
| <range> | No equivalent |
| <upload> | <input type="file"> |
| <select1> | <select> or <input type="radio"> |
| <select> | <select> or <input type="check"> |
Table 2.
Input, secret, and textarea all have similar counterparts in HTML. The XForms form controls, however, provide localization (for example, European users can enter “1,23” for a decimal number) and support for input modes, including eastern character sets and T9 predictive input on phone handsets.
Output is new in XForms, and provides a way to incorporate current information and summaries into form design.
Range is also new, providing smooth “volume control” selection from an ordered sequence.
Upload has a similar counterpart in HTML forms, but the XForms version accomplishes much more, and includes "device" upload, enabling microphones, scanners, cameras, and pen input.
Select and select1, finally, express the concepts of picking many or one items from a list. List selection items may be inline, as in HTML, or dynamic, based on instance data.
Form controls uniformly accept certain child elements that allow authors to provide additional information and functionality:
| Help |
Text and markup describing a help message, available on request |
| Hint |
Text and markup describing a hint shown as needed |
| Alert |
Additional text and markup for an additional alert message |
| XForms Actions |
Described in a following section. |
Beyond individual form controls, XForms also specifies:
| Group |
to logically group form controls and other markup |
| Switch |
to dynamically present one of many possible options |
| Repeat |
to present repeating structures, such as "line items" |
A number of various XPath constraints and computations can be applied to the form data, using specific attributes on binding elements:
| Required |
Is this node required to be non-empty? |
| Reaonly |
Is this node restricted from changing? |
| Relevant |
Should the user interface for this node be presented? |
| Calculate |
Compute the value of this node by the given expression. |
In the course of form processing, often some particular action needs to happen. The XForms specification builds upon [XML Events], to trigger actions in response to various events. Individually, each XForms Action replaces only a small amount of script, but taken as a whole and in various combinations, about 80% of the most common scripting can be eliminated.
| XForms Action | Description | Similar JavaScript |
|---|---|---|
| setfocus | Gives focus to a particular form control | Control.focus(); |
| setvalue | Sets the value of a particular node | Control.value = val; or list iteration setting selected attributes |
| message | Displays a message to the user | alert( "message"); |
| send | Submits all or part of the instance data | Form.submit(); |
| reset | Resets all or part of the instance data | Form.reset(); |
| load | Opens a new document | document.location = x; |
| refresh | Refreshes the view of the instance data | N/A |
| recalculate | Recalculates the instance data | N/A |
| revalidate | Revalidates the instance data | N/A |
| setindex | Navigates through a repeating sequence | N/A |
| insert | Inserts a node into a repeating sequence | InsertNode(...); |
| delete | Removes a node from a repeating sequence | RemoveNode(...); |
| toggle | Dynamically renders specific content | N/A |
| script | Execute arbitrary script (from host language) | N/A |
| dispatch | Dispatch an XML Event | dispatchEvent(evt); |
Table 3.
The XForms specification uses and builds upon XPath, which includes adding some method calls useful for forms:
| Method | Description |
|---|---|
| avg() | Returns the arithmetic mean |
| min() and max() | Returns the minimum/maximum |
| count-non-empty() | Counts the number of non-empty nodes |
| if() | Returns one of two strings depending on a Boolean evalutation |
| boolean-from-string() | Converts "true" or "false" into a Boolean value |
| index() | Gets the current position in a repeating sequence |
| property() | Returns various properties of the XForms Processor |
| now() | Returns the current date/time |
Table 4.
These can be called at any point where XPath is allowed. Additionally, implementations may support common "extension functions", including many from EXSLT [EXSLT], to provide additional functionality.
XForms Processing maintains the instance data in an internal XML structure. Upon submit, the XML is serialized into one of the following formats before sending over the wire:
| application/x-www-urlencoded |
Internationalized equivalent to the GET method in classic HTML forms |
| multipart/form-data |
Similar to the POST method in classic HTML forms |
| multipart/related |
An XML-optimized variation of multipart/form-data |
| application/xml |
Sending XML data |
| Others |
Custom XML-related media types can easily be used, including application/xhtml+xml |
In mid-October 2003, XForms 1.0 was finalized as a W3C Recommendation. A smaller part if the specification, detailing the "XForms Basic" conformance level, remained as a Candidate Recommendation, awaiting further work and participation from small device vendors.
At the pre-Recommendation stage, the XForms specification set an all-time record for the most implementations af W3C specification prior to Recommendation. A wide variety of XForms engines are underway, with several already meeting the full conformance level. The xml.com article "Ten Favorite XForms Engines" [xml.com]outlines many of them. Implementation platforms include Java, Internet Explorer plug-ins, Flash, and several server-side transformations.
The development of classic HTML forms led to the interactive Web. XForms has the potential to launch a second wave of XML-based Internet applications. So, I will conclude with a few predictions:
XForms will displace a number of incompatible proprietary XML forms formats.
Vendor interoperability will be much better, but still not perfect, using XForms as an exchange format.
XForms will find acceptance in servers first, and later in mainstream browsers.
Despite their shortcomings, classic HTML forms will never completely die.
By late 2005, mainstream public US and UK Government forms will use XForms technology.
.
Much of this material is taken from O'Reilly XForms Essentials; used with permission.
[XForms Essentials] Published by O'Reilly and associates, 2003. Full text available online at http://dubinko.info/writing/xforms/.
[XForms 1.0] W3C Recommendation track document: http://www.w3.org/TR/xforms/
[XML Events] W3C Recommendation track document: http://www.w3.org/TR/xml-events/.
[EXSLT] Web site:http://www.exslt.org
[xml.com] Article "Ten Favorite XForms Engines" at: http://www.xml.com/pub/a/2003/09/10/xforms.html
![]() ![]() |
Design & Development by deepX Ltd. |