Understanding the Form Engine
In creating your own VoiceXML applications, it’s important to understand the background logic used by the VoiceXML server to process a VoiceXML form. As we’ve seen, a <form> element can include multiple <block> and <field> elements. But what’s not obvious is that each block and field has its own internal variable, initially set to undefined. For a field, the name of the internal variable is the same name as the name of the field. For a block element, if a name attribute exists, that’s the name of the internal variable. If no name attribute is present, the system assigns its own internal variable name.
<form> <field name="foo"> .. </field> <block name=bar"> ... </block> <block name=bar"> .. </block> </form>
These behind-the-scenes variables are important because the voice server uses them to control which form or block the user hears. When the server executes a form, it looks for the first block or field with an undefined variable value, and executes it. For a block, as soon as the server begins to execute block content, its variable is set to a true so that it will not be revisited.
For a field, the internal variable gets set only when the user has entered valid data for the field. That’s why, if the user doesn’t enter a grammatically correct value, the field is re-entered. When all fields in the form have been filled by grammatically correct responses, any blocks that appear at the end of the form will be executed. That’s why in Listing 1, we place the submit element in the final block for execution. When the last block contains a submit element, it’s like pressing the SUBMIT button on a web form.