Using XForms


To generate XForms XML simple specify format="xml" in the <cfform> tag. Here is a simple example:

 <cfform format="xml"         action="process.cfm"> <cfinput name="nameFirst"          label="First Name:"          type="text"> <cfinput name="nameLarst"          label="Last Name:"          type="text"> <cfinput name="btn"          type="submit"          value="Process"> </cfform> 

The above code contains no formatting, and yet if processed by ColdFusion would generate a form formatted and laid out in an HTML table. As no skin was specified, the default skin was used, and if you look at the generated source (do a View Source in the browser) you will see that an HTML table was generated automatically (by the XSL transformation).

Applying XSL Skins

To use one of the provided skins, the <cfform> can be modified so that it reads:

 <cfform format="xml"         skin="silver"         action="process.cfm"> 

This will generate a nicely formatted form using a silver theme. By simply specifying an alternate skin a different output could be generated. The following skins are included with ColdFusion:

  • basic.xsl

  • basiccss.xsl (basic alignment using CSS instead of tables)

  • beige.xsl

  • blue.xsl

  • bluegray.xsl

  • red.xsl

  • silver.xsl

The provided skins are intended to be examples and starting points for your own skins. And once written, your own skins can be used just as easily. Consider the following example:

 <cfform format="xml"         skin="mySkin"         action="process.cfm">   <cfformgroup type="myLayout">     <cfinput name="nameFirst"              label="First Name:"              type="text">     <cfinput name="nameLarst"              label="Last Name:"              type="text">     <cfinput name="btn"              type="submit"              value="Process">   </cfformgroup> </cfform> 

In this example a skin named mySkin is being used, and any and all formatting and presentation is included within that XSL file. A <cfformgroup> is used to group fields together, and ColdFusion allows any group type to be used because it actually does nothing with the specified type, other than simply include it in the generated XML (which is then translated by the XSL skin). The XSL file would have to know what to do with a type of myLayout and would render presentation accordingly.

XSL Skin Locations

XSL skins can be shared system skins or application specific skins.

  • Any skins saved in /cfide/scripts/xsl (under the Web root) are system skins. These can be shared by all developers, and are referred to by the file name (without the .xsl extension).

  • Skins may also be located in the current directory (where it can be referred to by name) or in any other directory (where it must be referred to using a path). These skins may not be available to all developers, and when used the full file name (including the .xsl extension) must be used.

Usage Notes

A few important notes pertaining to XForms and their use within ColdFusion:

  • ColdFusion can help generate the XForms XML and can apply the transformation server-side, but XSL creation is left to the developer.

  • XForms can support any client-side technology, including HTML, JavaScript, DHTML, and more.

  • ColdFusion generated XForms does not write any client code for you, it simply generates the client code that you specify. In other words, you have to write exactly what you write now, but instead of placing it all in a single file it is now broken into two parts (the form contents and the form presentation).

  • The real value of XForms becomes apparent with the XSL contains not just colors and layout, but also form intelligence and logic (via scripting, perhaps).

NOTE

If you are looking for additional examples of XSL skins and use, visit http://www.cfform.com/.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net