Appendix C: Sample Forms


Contents

C.1 XForms and XHTML

XHTML Document with Multiple XForms - Page.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xml:lang="en" lang="en" 
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
  xmlns:xfm="http://www.w3.org/2000/12/xforms">

<head>
  <title>Sample XForms Document</title>
  <xform xmlns="http://www.w3.org/2000/12/xforms">

    <submit id="sub-a" target="http://example.com/app1" />
    <submit id="sub-b" target="http://example.com/app2" />

    <!-- Define the XForms Model for the opinion poll -->

    <model id="poll">
      <simple>
        <number name="choiceCode" enum="closed">
          <value>-1</value>
          <value>10</value>
          <value>20</value>
          <value>30</value>
        </number>
      </simple>
    </model>

    <!-- Define the XForms Model for the search -->

    <model id="search">
      <schema xmlns="http://www.w3.org/2000/10/XMLSchema">
        <element name="query">
          <complexType>
            <attribute name="searchstring" type="string" />
          </complexType>
        <element>
      <schema>
    </model>

    <!-- pre-initialized instance data for the search form -->

    <instance model="search" xmlns="http://example.org/ns">
      <query searchstring="Enter your Query Here" />
    </instance>

    <bind id="Query" ref="instance::search/query/searchstring"/>

  </xform>
</head>

<body>
  <!-- ... -->

  <!-- Site Search Markup -->
  <xfm:textbox ref="id('Query')">
    <xfm:caption>Search our Web Site<xfm:caption>
    <xfm:help>Enter your search term here and hit "Go!"</xfm:help>
  </xfm:textbox>
  <xfm:submit ref="instance::sitesearch" to="sub-a">
    <xfm:caption>Go!</xfm:caption>
  </xfm:button>  

  <!-- ... -->

  <!-- Daily Poll Markup -->
  <xfm:exclusiveSelect style="list-ui: radio" ref="model::poll/choiceCode">
    <xfm:caption>When do you plan to implement XForms?</xfm:caption>
    <xfm:item value="-1">Don't know</xfm:item>
    <xfm:item value="10">0-6 Months</xfm:item>
    <xfm:item value="20">6-12 Months</xfm:item>
    <xfm:item value="30">More than 12 Months</xfm:item>
  </xfm:exclusiveSelect>
  <xfm:submit ref="model::poll" to="sub-b">
    <xfm:caption>Submit</xfm:caption>
  </xfm:submit>

  <!-- ... -->

</body>
</html>
This is an example of a single document that might be hand authored. This example shows an XHTML document with two separate XForms embedded using simple syntax, one with a set of initial instance data.
Sample Instance Data for Poll
<choiceCode>30</choiceCode>

Here is a sample of the instance data for the Poll form.

Sample Instance Data for Site Search
<query xmlns="http://example.com/ns" searchstring="MP3" />

Here is a sample of the instance data for Site Search form.