Volume 2, Issue 3 - April/May 2002
   
 

Some Questions on VoiceXML 2.0

By Matt Oshry

(Continued from Part 1)

Q: I'm trying to implement a sign-in dialog. It consists of three dialogs. The first asks for the user's id,
the second asks for their password, and the third submits the information to a server-side script
for validation. The trouble is, when I get to the submission dialog, the variables containing the id and pin appear to be no longer available. What can I do?

A: Ah, variable scoping. Understanding how variables are scoped by a language is an important step in attaining mastery of the language. You can tackle this problem in a couple of ways.

Sticking with your current three dialog design, the first solution is to create variables that hold the id and password at document scope. In the filled element of the id and password dialogs, you use the assign
element to copy the contents of the variable associated with the name attribute of the field element to the corresponding variable at document scope. For example, consider the following dialog that fetches a five-digit user id:

<vxml version="2.0">
<!-- store copies of id/pwd at document scope -->
<var name="id" />
<var name="pwd" />

      <form id="get_id">
         <field name="id">
         <prompt>Please enter your five digit id</prompt>
               <grammar src="builtin:digits?length=5"/>
               <catch event="noinput nomatch">
               Sorry. I didn't get that.
               <reprompt/>
               </catch>
               <filled>
               <assign name="document.id" expr="id"/>
               <goto next="#get_pwd"/>
               </filled>
          </field>
      </form>

      <form id="get_pwd">
           <field name="pwd">
                  <prompt>Please enter your four digit password</prompt>
                  <grammar src="builtin:digits?length=4"/>
                  <catch event="noinput nomatch">
                  Sorry. I didn't get that.
                  <reprompt/>
                  </catch>
                  <filled>
                  <assign name="document.pwd" expr="pwd"/>
                  <goto next="#validate"/>
                  </filled>
            </field>
      </form>

      <form id="validate">
           <block>
               <submit next="validate.cgi" namelist="id pwd"/>
            </block>
       </form>
 </vxml>



Note that, because the document-scoped variables have the same name as the form item variables in the get_id and get_pwd dialogs, we need to explicitly specify the scope of the variable to which we want to assign the value. If we didn't explicitly specify the scope, we'd end up assigning the variable to itself.

As an alternative to splitting the collection of id and password and submitting those values into three separate dialogs, consider implementing them in a single dialog consisting of two fields and a block. This avoids the scoping issue altogether as well as the need to make the temporary assignments. The implementation might look something like the following:

<vxml version="2.0">
<form id="signin">
<field name="id">
<prompt>Please enter your five digit id</prompt>
<grammar src="builtin:digits?length=5"/>
<catch event="noinput nomatch">
Sorry. I didn't get that.
<reprompt/>
</catch>
</field>

      <field name="pwd">
           <prompt>Please enter your four digit password</prompt>
            <grammar src="builtin:digits?length=4"/>
            <catch event="noinput nomatch">
            Sorry. I didn't get that.
            <reprompt/>
            </catch>
      </field>

      <block>
      <submit next="validate.cgi" namelist="id pwd"/>
      </block>
   </form>
</vxml>


 

 

back to the top

Copyright © 2001-2002 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE Industry Standards and Technology Organization (IEEE-ISTO).