XML
  Home arrow XML arrow Page 6 - XForms Basics
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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: 4 stars4 stars4 stars4 stars4 stars / 38
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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.
     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    XML ARTICLES

    - 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...
    - SimpleXML
    - XForms Basics, Part 3
    - XForms Basics, Part 2
    - XForms Basics

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway