XML
  Home arrow XML arrow Page 6 - XForms Basics, Part 2
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 
IBM Developerworks
 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, Part 2
By: Harish Kamath, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2004-01-14

    Table of Contents:
  • XForms Basics, Part 2
  • Welcome to Immigration
  • Data Overload
  • A Custom Job
  • Not My Type
  • The Number Game

  • 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

    Dell PowerEdge Servers

    XForms Basics, Part 2 - The Number Game
    (Page 6 of 6 )

    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:


    <html 
      xmlns
    =http://www.w3.org/1999/xhtml
      xmlns:xforms=
      "http://www.w3.org/2002/xforms/cr">
     
    <head>
     
    <!-- 
    form model -->
    <xforms:model id="information" 
      schema
    ="users.xsd">
     
    <xforms:instance>
      
    <user>
       
    <name xsi:type="xsd:string"  />
       
    <email xsi:type="xsd:string" />
       
    <age xsi:type="adultsOnly" />
      
    </user>
     
    </xforms:instance>
     
    <xforms:submission id="submit" 
       ref
    ="/user/name" 
       action
    ="/scripts/save.cgi" 
       method
    ="post" indent="yes" 
       omit
    -xml-declaration="no" />
    </xforms:model>
     
    <
    basefont face="Arial">
     
    </
    head>
     
    <
    body>
     
    <!-- 
    define interface controls -->
    <table cellspacing="5" cellpadding="5" 
      border
    ="0">
    <tr>
    <td>
     
    <xforms:input 
       id
    ="txtname" 
       model
    ="information" 
       ref
    ="/user/name">
      
    <xforms:label>
            Name
      
    </xforms:label>
      
    <xforms:hint>
            Enter your name here
      
    </xforms:hint>
     
    </xforms:input>
    </td>
    </tr>
    <
    tr>
    <td>
     
    <xforms:input id="txtemail" 
       model
    ="information" 
       ref
    ="/user/email">
      
    <xforms:label>
            Email address
      
    </xforms:label>
      
    <xforms:hint>
            Enter your email address here
      
    </xforms:hint>
     
    </xforms:input>
    </td>
    <
    td>
     
    <xforms:input id="intage" 
       model
    ="information" 
       ref
    ="/user/age">
      
    <xforms:label>
      Age
      
    </xforms:label>
      
    <xforms:hint>
      Enter your age here
      
    </xforms:hint>
     
    </xforms:input>
    </td>
    </
    table>
    <
    xforms:submit submission="submit">
     
    <xforms:label>Save</xforms:label>
    </xforms:submit>
    </
    body>
    </html>

    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:schema 
     xmlns:xsd=
     "http://www.w3.org/2001/XMLSchema">
     <xsd:simpleType name="adultsOnly">
      <xsd:restriction base="xsd:integer">
       <xsd:minInclusive value="18" />
      </xsd:restriction>
    </xsd:simpleType>
    </xsd:schema>

    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.


    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 4 hosted by Hostway