2   Forms

The main elements of a document (within the <vxml> element) are forms. VoiceXML forms are analogous to web forms; you use them to collect (voice) input from the user.

This chapter describes:

 •  Form Items
 •  Form-Item Variables
 •  Execution of a Form
 •  User Interaction

Form Items

So far, the only form item we've discussed is the <field> element. However, forms can contain either input items or control items:

Input items are elements for collecting user input or results. An input item is any one of the following:

 •  A field, defined with the <field> tag, asks the user for a piece of information.
 •  A record item, defined with the <record> tag, records what the user says (perhaps for a voicemail message);
 •  A subdialog, defined with the <subdialog> tag, invokes a reusable dialog.
 •  A transfer item, defined with the <transfer> tag, transfers the user to another telephone number.

Control items are tags that can contain procedural items for audio output or computation. A control item is either of the following:

 •  A block, defined with the <block> tag, is a container for procedural elements.
 •  An initial item, defined with the <initial> tag, controls the initial interaction of a mixed-initiative form.

Form-Item Variables

Each form item has an associated form-item variable. When a form is entered, all form-item variables are initially undefined. When a form item is visited, its variable is set to the result of interpreting that form item. For example, visiting a <block> element sets its form-item variable true. The form-item variable for an input item is also called an input-item variable (or simply input variable); after an input item is visited, its input-item variable is set to the value collected from the user.

For more details on setting form-item and input-item variables, see the Grammar Reference.

Execution of a Form

Within a form, the flow of execution is governed by the Form Interpretation Algorithm (FIA), a looping algorithm. On each iteration, the FIA selects the form item to visit next.

A form item's guard conditions determine whether it can be selected on a given iteration:

 •  The value of the form-item variable must be undefined.
 •  The value of any cond expressions contained in the form item must evaluate to true.

Both guard conditions must be met in order for a form item to be selected. The FIA examines the form items in document order, selecting the first one whose guard conditions are met. If the guard conditions for all form items fail, the form (and the application) exits.

By default, every form-item variable has an initial value of undefined so every form item that does not specify a cond expression is eligible for selection. After the form item is visited, its variable is set to a value, which prevents the same form item from being selected again on the next iteration.

You can explicitly control the execution of any form item if you give its variable a name and an initial value other than undefined. Doing so prevents the form item from being eligible for selection until you explicitly use the <clear> tag to reset its variable. Typically, input-item variables are given names but control-item variables are not.

User Interaction

User interaction with a form can be directed or mixed initiative.

A directed form has no form grammar, only grammars for its individual fields. A directed form gives the user explicit directions about what to say and when. For example, a directed form might result in the following dialog:

Application:

Would you like to buy, sell, or receive a stock quote?

User:

Get a quote.

Application:

What stock or stocks would you like a quote for?

User:

Intel.

A form that includes its own grammar is a mixed-initiative form. The form grammar allows several input variables to be filled in as a result of a single user utterance. A mixed-initiative form allows the user to speak more naturally. For example, a mixed-initiative form might result in the following dialog.

Application:

Stock assistant here. How can I help you?

User:

I'd like to get a quote for Intel.

One disadvantage of mixed-initiative forms is that form grammars are more complicated and can result in more recognition errors.

The grammar for a field sets a value for the field's variable. For example, the grammar in the following field, specified in ABNF, assigns the value june to the variable month if the user says "June."

 <field name="month">
   <grammar>
     #ABNF 1.0;
     root $mo;
     $month = june | july |august;
   </grammar>
 <field>

The grammar for a form must specify both the input variable to be set by a grammar rule and the value for that variable. For example, the ABNF grammar in the following file, foo.gram, sets values for two variables, quantity and fruit:

 #ABNF 1.0;
 root $main;
 $main = 
     [$amount] $fruit
   | $amount [$fruit]
   | $amount $fruit
 ;
 $amount =
     one   { quantity=1 }
   | two   { quantity=2 }
   | three { quantity=3 }
 ;
 $fruit =
     (apple | apples)   { fruit=apples }
   | (orange | oranges) { fruit=oranges }
 ;

This grammar is used by the following mixed-initiative form:

 <form id="foo">
   <grammar src="foo.gram#main"/>
   <initial>
     <prompt>How many apples or oranges do you want?</prompt>
   </initial>
   <!-- If user doesn't respond to initial -->
   <!-- prompt, ask for each field -->
   <field name="fruit">
     <grammar src="foo.gram#fruit"/>
     <prompt>Do you want apples or oranges?</prompt>
   </field>
   <field name="quantity">
     <grammar src="foo.gram#amount"/>
     <prompt>How many <value expr="fruit"/> do you want?</prompt>
   </field>
   <filled>
     <prompt>
       Ok, you want <value expr="quantity"/> <value expr="fruit"/>
     </prompt>
   </filled>
 </form>


[Show Frames]   [FIRST] [PREVIOUS] [NEXT]
BeVocal, Inc. Café Home | Developer Agreement | Privacy Policy | Site Map | Terms & Conditions
Part No. 520-0001-02 | © 1999-2007, BeVocal, Inc. All rights reserved | 1.877.33.VOCAL