Tellme More - Mother of Perl | 4 | WebReference

Tellme More - Mother of Perl | 4

To page 1To page 2To page 3current pageTo page 5To page 6To page 7
[previous] [next]

Tellme More

Handling Events

Invalid Input

Handling forms requires more than simply gathering field input. If the user provides input that doesn't match the grammar, Tellme will look for the nomatch element. If it doesn't exist, the application will croak. The most common way to handle invalid input is to tell the user so and ask them for the information again.

<?xml version="1.0"?>
<vxml version="1.0" > 
  <form id="hello"> 
    <field name="pin"> 
      <grammar>
		    <![CDATA[
       				Four_digits
     			]]>
      </grammar>	
      <prompt>Please enter your 4 digit pin code.</prompt> 
  	   <filled>
  	     <submit next="http://www.webreference.com/cgi-bin/perl/20/pin.pl"/>
      </filled> 
      <nomatch>Invalid pin code.
        <reprompt/>
      </nomatch>
    </field> 
  </form>
</vxml>

In the example above, we are using one of the Tellme grammars, Four_digits, to regulate the input. The grammar contains rules that will cause the document to call the nomatch event unless the user enters four numbers via the phone keypad or by voice. The reprompt element repeats the last prompt, Please enter your 4 digit pin code after telling the user that they've entered an invalid PIN code. Tellme will keep reprompting the user as long as they keep entering invalid input.

Of course, if the user is repeatedly entering invalid input, giving them the same error message and prompt won't help the user any. In fact, it would be downright user unfriendly. This is why the nomatch element includes a count attribute that allows us to give the user a different warning message each time the nomatch event is called.

      <nomatch count="1">Invalid pin code.
        <reprompt/>
      </nomatch>
      <nomatch count="2">Please press or say exactly four numbers.
        <reprompt/>
      </nomatch>
      <nomatch count="3">Too many attempts. Please call back 
                         another time.
        <exit/>
      </nomatch>			
		

Now, the second time the user provides bad input, we give them more specific instructions, "Too many attempts. lease call back another time." The third time the user provides bad input, we exit the program.

No Input

Like handling invalid input, it's also critical to handle no input. Tellme calls the noinput event when the user does not provide any input after a prompt has been played.

<?xml version="1.0"?>
<vxml version="1.0" > 
  <form id="hello"> 
    <field name="pin"> 
      <grammar>
		    <![CDATA[
       				Four_digits
     			]]>
      </grammar>	
      <prompt>Please enter your 4 digit pin code.</prompt> 
  	   <filled>
  	     <submit next="http://www.webreference.com/cgi-bin/perl/20/pin.pl"/>
      </filled> 
      <noinput>
        <reprompt/>
      </noinput>
      <nomatch>Invalid pin code.
        <reprompt/>
      </nomatch>
    </field> 
  </form>
</vxml>

Like the nomatch element, if you don't handle the noinput event, your VoiceXML application will return an error when it's called. Also, like nomatch, you can set the count attribute so that a different message is played each time the user fails to provide input.

      <noinput count="1">No PIN entered.
        <reprompt/>
      </noinput>
      <noinput count="2">You must enter your PIN number to proceed.
        <reprompt/>
      </noinput>
      <noinput count="3">Please press or say exactly four numbers.
      </noinput>
		

If the noinput event is called more than 3 times, Tellme will continue to repeat the last noinput, "Please press or say exactly four numbers.", until the user provides some input.


To page 1To page 2To page 3current pageTo page 5To page 6To page 7
[previous] [next]

http://www.internet.com

Produced by Jonathan Eisenzopf
All Rights Reserved. Legal Notices.
Created: February 23, 2001

URL: http://www.webreference.com/perl/tutorial/20/4.html