Home arrow XML arrow Page 6 - XForms Basics, Part 2

The Number Game - XML

In the first part of this series, I gave you a quick introduction to the newly-released XForms 1.0 specification, by explaining the fundamental concepts of the XForms model. Now that you know the basics, find out how to submit XForms data to a server-side script or save it to a local client file, and also read about how XForms can integrate with XML Schemas to simplify input validation.

  1. XForms Basics, Part 2
  2. Welcome to Immigration
  3. Data Overload
  4. A Custom Job
  5. Not My Type
  6. The Number Game
By: Harish Kamath, (c) Melonfire
Rating: starstarstarstarstar / 8
January 14, 2004

print this article



If you have special needs, you can even create your own datatypes using XML Schema, instead of restricting yourself to the pre-defined datatypes. Consider the following example:

form model -->
<xforms:model id="information" 
<name xsi:type="xsd:string"  />
<email xsi:type="xsd:string" />
<age xsi:type="adultsOnly" />
<xforms:submission id="submit" 
="post" indent="yes" 
-xml-declaration="no" />
basefont face="Arial">
define interface controls -->
<table cellspacing="5" cellpadding="5" 
        Enter your name here
<xforms:input id="txtemail" 
        Email address
        Enter your email address here
<xforms:input id="intage" 
  Enter your age here
xforms:submit submission="submit">

You'll notice that I've defined a custom type in the form model something called "adultsOnly". The definition for this type is stored in an XML Schema, and it only allows you to enter values equal to or over 18 into the corresponding field. Take a look:

<?xml version="1.0" encoding="UTF-8"

 <xsd:simpleType name="adultsOnly">
  <xsd:restriction base="xsd:integer">
   <xsd:minInclusive value="18" />

And that's about it for today. In this article, I began by discussing the XForms submission process, and explained how to use the <xforms:submission> element to save form input to a local file with the PUT method, and how to pass it to a server-side script for storage in a MySQL database. I also showed you a real-world example of the latter, by using the PHP SAX parser to parse the instance document generated by an XForms submission and convert it into an SQL query string.

Next, I taught you how XForms significantly simplifies the task of input validation, by integrating with XML Schema datatypes and allowing you to validate user input against those datatypes. Here too, I showed you a couple of different examples, one using XML Schema built-in datatypes and the other using my own custom types.

Next time, I'll be delving a little deeper into the XForms specification, explaining binding, form events, and built-in functions. Until then, stay healthy!

Note: Examples are illustrative only, and are not meant for a production environment. Melonfire provides no warranties or support for the source code described in this article.

>>> More XML Articles          >>> More By Harish Kamath, (c) Melonfire

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Google Docs and Xpath Data Functions
- Flex Array Collection Sort and Filtering
- The Flex Tree Control
- Flex List Controls
- Working with Flex and Datagrids
- How to Set Up Podcasting and Vodcasting
- Creating an RSS Reader Application
- Building an RSS File
- An Introduction to XUL Part 6
- An Introduction to XUL Part 5
- An Introduction to XUL Part 4
- An Introduction to XUL Part 3
- An Introduction to XUL Part 2
- An Introduction to XUL Part 1
- XML Matters: Practical XML Data Design and M...

Developer Shed Affiliates


Dev Shed Tutorial Topics: