|
By Jennifer Kyrnin
If you've been building Web pages for a while, chances are you have used, or are
planning to use forms. HTML forms allow you to create dynamic pages that include
information that your readers provide. They can also collect data from customers
to provide services or ecommerce. But with the advent of XML and XHTML, it is now
clear that HTML forms have some severe limitations. Specifically:
- The purpose of the form is combined with the presentation
- Forms in HTML don't integrate well with XML
- HTML forms are not very accessible
- They are only viewable on Web browsers
- Limited user interface
- No logic embedded in the forms
The goal of XForms is to address these issues with HTML forms, and solve them.
- Separation of the purpose of the form from the presentation
- Clear integration with XML
- Accessible
- Device independent
- Richer user interface to meet needs of businesses, consumers, and
applications
- Advanced forms logic
Purpose vs. Presentation
The original intent of HTML was to markup the content of documents. This included
tags such as <code> and <p> that defined the contents but not how they
should look. This was rapidly changed to include indications for how to display the
data. These included tags like <font> that defined exactly how the contents
should be presented in the Web window.
XML brought the point of XHTML back to defining the purpose of the data, rather than
how they should look on the screen. And XForms does the same for HTML forms. In fact,
XForms has divided forms into three parts:
- purpose
For example: data collection
- presentation
the arrangement of form controls on the screen
- data
registration information
XForms are made up of separate sections that define what the form does and how it is
to be displayed. This means that you can use the same form and have it displayed on
Web browsers, handheld devices, and other applications.
Comparing XForms to HTML Forms
Here is a simple HTML form:
<form action="form.cgi">
<table>
<tr>
<td>Title:</td><td><input type="radio" name="title" value="Mr.">Mr.
<input type="radio" name="title" value="Ms.">Ms.</td>
</tr>
<tr>
<td>Name:</td><td><input type="text" size="20" name="name"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="Register"></td>
</tr>
</table>
</form>
In HTML, the form is defined with both the layout and form information included in the
document. Using XForms the previous form might be written like this:
<xform:selectOne ref="title">
<xform:caption>Title</xform:caption>
<xform:choices>
<xform:item value="Mr."><xform:caption>Mr.</xform:caption></xform:item>
<xform:item value="Ms."><xform:caption>Ms.</xform:caption></xform:item>
</xform:choices>
</xform:selectOne>
<xform:input ref="name">
<xform:caption>Name</xform:caption>
</xform:input>
<xform:submit>
<xform:caption>Register</xform:caption>
</xform:submit>
Some things to note
- Instead of defining the "select one and only one" element as a radio button, it is
defined as the "purpose" rather than the "presentation". Thus, if this form were to
be put into VoiceML it would still work as designed.
- The captions are included as child elements of each corresponding form
element.
- Data submitted through this form will be submitted as XML
Results
One of the best aspects of XForms is that the data is processed and submitted as XML.
The captions (which are required), are used to create an XML document. For example,
the above XForms document would create the following XML output:
<!-- container element added separately -->
<container>
<title>Ms.</title>
<name>Jennifer Kyrnin</name>
<!-- container element added separately -->
</container>
XForms is a new standard for creating and maintaining forms in XML.
Previous Features
|