Section 9.2.  Using a form

Prev don't be afraid of buying books Next

9.2. Using a form

Worldwide Widget Corporation has an award-winning logo merchandising program. Although its widgets have lost money from the beginning, the company makes a healthy profit from its popular line of "Widget Wear", emblazoned with its distinctive "W2C" logo.

Worldwide's order clerks have quickly become comfortable with InfoPath because of its similarity to their other Office tools. With most forms software, end users operate in "form completion" mode, filling in the blanks. The InfoPath end user environment offers much more flexibility than a typical forms package, with many familiar features from the other Office products.

For this reason, Microsoft refers to the forms completion process as forms editing.

Just as when working with XML in Word, the document on the screen is a rendition of an underlying abstract XML document. However, users normally do not need to know that they are editing an XML document, let alone understand its structure. They simply enter data into the form with help from the various features of InfoPath.

This is known as working in edit mode. Edit mode allows users to enter and modify data, and to open and save documents. The users cannot affect the design of the form.

9.2.1 Opening an empty form

Upon launching InfoPath, the Fill Out a Form task pane appears on the right side of the window. There are several ways to bring up an empty form to begin entering data:

  • You can select a form in the Fill out a form section of the task pane. This will immediately bring up the form associated with that name.

  • You can click On My Computer or On My Web Sites from the Open a form section of the task pane. This will allow you to browse for form files on your computer or on the Web.

  • You can click Open on the File menu, then select a file and click Open. If you choose a form file (with a .xsn extension), InfoPath will open a blank form of that kind. If you choose an XML document, InfoPath will open that document as a form.

To use the Worldwide example, choose either of the last two options. Select the order.xsn file and click Open. This will bring up an order form, shown in Figure 9-1.

Figure 9-1. The order form (order.xsn)




9.2.2 The InfoPath environment

InfoPath offers a familiar environment that is consistent with the rest of the Microsoft Office products. It has many of the same features as other Office products, including:

  • Cut, copy and paste

  • Spell check

  • Find and replace

  • Undo and redo

  • Select all

  • Print, print preview and page setup

Just as a spreadsheet mapped to an XML document has repeating and non-repeating cells, a form has repeating and non-repeating fields. In our example, Items is a repeating table. Its rows repeat for each item ordered, which means the five fields in a row are repeating fields.

9.2.3 Fields

Filling out the form is simply a matter of filling in the blanks. As you position the cursor over an editable field, its border becomes a dark gray. The Tab key can be used to move between fields. Fields that are required to contain data are underlined in red. In our example, the Number, Date and Product Number fields are required.

Every field has an associated datatype. Some, such as Customer Name, are simply strings, which allow any data to be entered. Others have specific types, such as dateTime for the Date field, and integer for the Quant field. Additional constraints can be placed on the contents of a field, as discussed in 9.3.4.2, "Field-based constraints", on page 199.

If you enter a value in a field that is invalid for the field's datatype, or violates a constraint, a red-dashed border will appear around the field. Right-clicking the field will bring up a description of the violation.

Controls can be used to change the appearance and/or capabilities of a field. Most fields in our form have ordinary text boxes for controls, but three fields are associated with other kinds of controls:

  • The Date field has a calendar control, which allows the user to select the date from a calendar.

  • The Comment field has a rich text box control, which allows the user to format the text of the comment by using fonts, sizes, colors, lists and styles.

  • The Size field has a drop-down list associated with it, allowing the user to select from the values Small, Medium or Large.

9.2.4 Tables

The last part of the order form is a table, which allows repeating items for the order. Only one row is initially displayed in the empty form. When the cursor is positioned in any field on the row, you can click the down arrow at the left of the row to bring up the table menu, shown in Figure 9-2. This menu allows you to insert and remove rows.

Figure 9-2. The table menu




As an exercise, fill in the order form with data, including more than one item in the table. The completed form will look something like Figure 9-3.

Figure 9-3. The completed order form




9.2.5 Saving and opening documents

Once the form is completed, you can save the data as an XML document. To do this, simply click Save on the File menu and specify a file name. Note that it is possible to save a document that contains errors; the resulting document simply won't be valid according to its associated schema.

The generated document is shown in Example 9-1. An end user will probably never have to look at it, but as we are going to be designing forms, it may be helpful to know what InfoPath is generating.

Example 9-1. Saved XML document (order1001.xml)
 <?xml version="1.0" encoding="UTF-8"?> <?mso-infoPathSolution productVersion="11.0.5531"                        PIVersion="1.0.0.0" href="order.xsn"                        language="en-us"                        solutionVersion="1.0.0.197" ?> <?mso-application prog?> <ns1:order number="1001"            xmlns:ns1="http://xmlinoffice.com/orders">   <ns1:date>2003-09-24T00:00:00</ns1:date>   <ns1:comment></ns1:comment>   <ns1:customer>Doug Jones</ns1:customer>   <ns1:shipTo>     <ns1:addr>123 Main St.</ns1:addr>     <ns1:addr2></ns1:addr2>     <ns1:city>Traverse City</ns1:city>     <ns1:state>MI</ns1:state>     <ns1:postal_code>49684</ns1:postal_code>   </ns1:shipTo>   <ns1:items>     <ns1:item number="334">       <ns1:desc>Wool Sweater</ns1:desc>       <ns1:quant>2</ns1:quant>       <ns1:size>M</ns1:size>       <ns1:price>59.99</ns1:price>     </ns1:item>     <ns1:item number="445">       <ns1:desc>Silk 2-Pocket Blouse</ns1:desc>       <ns1:quant>1</ns1:quant>       <ns1:size>S</ns1:size>       <ns1:price>47.99</ns1:price>     </ns1:item>   </ns1:items> </ns1:order> 

Note that there are two processing instructions at the beginning of the document. The first, labeled mso-infoPathSolution, indicates the form associated with this document, namely order.xsn.[1] This allows InfoPath to associate the document with the form when it is opened.

[1] Normally, the entire path is included; we have shortened it to simplify the example.

The second processing instruction, labeled mso-application, indicates that the program used to open this document should be InfoPath. Documents with a .xml extension that do not contain such a processing instruction are usually opened in a Web browser.

Instead of starting out with an empty form, you can open an existing XML document, edit it, and resave it. However, in order to open a document in InfoPath it must have the two processing instructions shown in Example 9-1. Otherwise, InfoPath will not know what form to associate with the document. This means that if the XML document was generated by some other process, those two instructions must be added before it can be used in InfoPath.

There are two ways to open an existing XML document in InfoPath:

  • You can click On My Computer or On My Web Sites from the Open a form section of the Fill Out a Form task pane.

  • You can click Open on the File menu, then select the file and click Open.

In either case, this will allow you to browse for files on your computer or on the Web. If you choose an XML document that has the appropriate processing instructions, it will be opened in InfoPath.

You can save your completed form as an XML document. In addition, you can export it to either an HTML page, or to Microsoft Excel. To export a completed form, click Export on the File menu.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

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