This information is in part taken from the O'Reilly book XForms Essentials. Used with permission.

What is 'XForms'?

If you browse the Web at all, you probably use forms more often than you realize. Nearly all on-line interaction (as opposed to static text delivery) takes place through some kind of form. To enhance the use of forms on the Web, the World Wide Web Consortium (W3C) sponsored the development of XForms.

Instead of further altering the existing forms language that is part of HTML, the W3C membership agreed that a new approach was necessary. Several years later, this has become XForms 1.0, an official Recommendation of the W3C.

Like XHTML, SVG, and RSS, XForms is an XML-based language written with tags that can be identified by surrounding angle brackets. (XML purists perfer to call these elements) Learning XForms is largely a matter of understanding what individual elements do, as well as how they interrelate. One difference is that XForms provides several more elements than form authors might be accustomed to. As a result, several tasks that would have otherwise required complicated scripting can be accomplished declaratively, just by putting the right elements in place.

Why "Lazy Authoring" is good

XForms was designed with the classic XHTML author in mind, so it includes a simplified approach that is easy to write and about as powerful as classic HTML forms without script. This is called, unofficially, "lazy authoring" as a tribute to the geek ethic of beneficially avoiding unnecessary work.

Structurally, a form can be throught of as having two parts: a specification of what it should do, and a specification of how it should look. In XForms these two parts are called, respectively, the XForms Model and the XForms User Interface. With lazy authoring, the XForms Model is little more than a boilerplate:

   <submission action="" method="get" id="s"/>

The action attribute contains the URL to which to form should be submitted, and the id attribute provides a unique name that we can refer to later. In XHTML, this section of code would usually appear in the head section of the document.

The user interface has more flexibility in how it can be written, as the next section shows.

Form Controls

Individual user interface elements in XForms are called form controls, each of which is represented by an element. The two most commonly used elements are input and submit.

In lazy authoring, form controls can be included anywhere in the main body of the document with a ref attribute that holds the name of the form control:

<input ref="query"><label>Search:d</label></input>
<submit submission="s"><label>Go!</label></submit>

Notice that each form control element has a required label child element, and that the submit element references the id of the submission element defined earlier.

Test your knowledge

In the area below, enter the markup necessary to define the following form controls:

  1. The user's first name, called "fname"
  2. The user's last name, called "lname"
  3. A submit button

Reference the XForms Model defined earlier on this page. When you are ready, click the button to reveal the correct answer.

View Source : Validate

In the next lesson, you will learn about more advanced features beyond lazy authoring.