XML
  Home arrow XML arrow Page 6 - XForms Basics
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XForms Basics
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 41
    2004-01-12


    Table of Contents:
  • XForms Basics
  • Out with the Old...
  • ... In With the New
  • What's In A Name?
  • Welcome to Nowhere
  • A Tour of Nowhere

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    XForms Basics - A Tour of Nowhere
    ( Page 6 of 6 )

    First up, the definition of the XForms model: unlike the previous example, I've defined the instance data tree in a separate file and imported it via the "src" attribute.


    <!-- form model -->
    <
    xforms:model id="immigration">
     <
    xforms:instance src="immigration.xml" />
    </
    xforms:model>
    <
    basefont face="Arial">

    Here's what "immigration.xml" looks like:


    <?xml version="1.0" encoding="iso-8859-1"


    <!-- immigration.xml -->
    <immigrant>
     <name />
     <citizenship />
     <purpose />
     <immunization />
     <address />
    </immigrant>

    You've already seen how to use an <xforms:input> element in previous examples, so I won't go into the details again. Do note, however, my usage of the <xforms:label> and <xforms:hint> elements within it. These come in handy to provide descriptive human-readable information about the control.


     <xforms:input id="txtname" model="immigration" 
    ref="/immigrant/name">
      <
    xforms:label>Name</xforms:label>
      <
    xforms:hint>
      
    Enter your name here
      
    </xforms:hint>
     </
    xforms:input>

    The <xforms:select1> element allows the user to select one item from a series of options:


     <xforms:select1 model="immigration" 
     
    ref="/immigrant/purpose" appearance="full">
      <
    xforms:label>Purpose of visit</xforms:label>
      <
    xforms:hint>
      
    Please state the purpose of your visit
      
    </xforms:hint>
      <
    xforms:item>
       <
    xforms:label>Business</xforms:label>
       <
    xforms:value>B</xforms:value>
      </
    xforms:item>
      <
    xforms:item>
       <
    xforms:label>Pleasure</xforms:label>
       <
    xforms:value>P</xforms:value>
      </
    xforms:item>
      <
    xforms:item>
       <
    xforms:label>Other</xforms:label>
       <
    xforms:value>O</xforms:value>
      </
    xforms:item>
     </
    xforms:select1>

    Within the <xforms:select1> element, the list of available choices is defined via one or more <xforms:item> elements, each of which must have a label and value; the former is displayed to the user and the latter is passed to the server on submission.

    A special "appearance" attribute in the <xforms:select1> element can be used to control the display of the element in the browser ("full" for a list of all values, "minimal" for a minimum number of values, and "compact" for a scrollable list).

    Similar, though not identical to the above, is the <xforms:select> element, which allows the user to select more than one value from the options available.


     <xforms:select model="immigration" 
     
    ref="/immigrant/immunization" appearance="full">
      <
    xforms:label>Immunization</xforms:label>
      <
    xforms:hint>
      
    Please select the diseases that 
      you have been immunized against
      
    </xforms:hint>
      <
    xforms:item>
       <
    xforms:label>Smallpox</xforms:label>
       <
    xforms:value>100</xforms:value>
      </
    xforms:item>
      <
    xforms:item>
       <
    xforms:label>Malaria</xforms:label>
       <
    xforms:value>113</xforms:value>
      </
    xforms:item>
      <
    xforms:item>
       <
    xforms:label>Yellow fever</xforms:label>
       <
    xforms:value>56</xforms:value>
      </
    xforms:item>
      <
    xforms:item>
       <
    xforms:label>Typhoid</xforms:label>
       <
    xforms:value>174</xforms:value>
      </
    xforms:item>
     </
    xforms:select>

    As before, the choices are defined via a series of <xforms:label> and <xforms:value> elements, while the "appearance" attribute can be used to control the appearance of the control ("full" for a list of all values, "minimal" for a minimum number of values, and "compact" for a scrollable list).

    Finally, the <xforms:textarea> element is used to display a multi-line text entry box, suitable for use with large blocks of text.


     <xforms:textarea model="immigration" 
     
    ref="/immigrant/address">
      <
    xforms:label>
      
    Address in home country
      
    </xforms:label>
     </
    xforms:textarea>

    And here's what it all looks like:

    Now, all this is fine and dandy, but how about submitting the form and actually doing something with the user's data?

    Well, that's a whole new kettle of fish, one which involves jumping through a complicated series of hoops involving the <xsd:submission> element. I don't plan to discuss it now. Instead, I'm going to defer it to the second segment of this tutorial and encourage you to spend the interim playing with the various form controls to understand how they work. Each control comes with specific properties that can be used to customize its behavior, so take a look at the specification, get comfortable with them, try out a couple of implementations, and come back next week to take the next step in our XForms journey!

    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
     

       

    XML ARTICLES

    - 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...
    - Practical XML Data Design and Manipulation f...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT