| VoiceXML 2.1 Development Guide | Home | Frameset Home |
|
<form> level will be given dialog scope, while variables declared at the <vxml> level will be given document scope. Variables declared at the <vxml> level within the application root document will inherit application scope.<form> of a document will not be available within the second <form>, unless it is passed along via a <submit>, or if it is explicitly assigned a higher scope while within the <form>.<block> or within a <field>. They will only be considered active when the application visits and executes these form items.
<value expr="application.MyVar"/>
<value expr="document.MyVar"/>
<value expr="dialog.MyVar"/>
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0">
<meta name="maintianer" content="yourEmail@here.com"/>
<var name="DocumentVar" expr="'document'"/>
<!-- IT IS IMPORTANT TO REMEMBER *NOT* TO ASSIGN ANY VARIABLES
WITH AN 'application' PREFIX WITHIN THE ROOT DOCUMENT ITSELF,
ELSE AN ERROR.SEMANTIC WILL BE THROWN:
<var name="application.ApplicationVar" expr="'application'"/>
-->
<var name="ApplicationVar" expr="'application'"/>
<form id="F1">
<var name="DialogVar" expr="'dialog'"/>
<block>
<prompt>
here we have a <value expr="DialogVar"/> scoped variable.
</prompt>
<goto next="#F2"/>
</block>
</form>
<form id="F2">
<block>
<var name="AnonVar" expr="'anonymous'"/>
<prompt>
Our anonymous scoped variable is available here,
<value expr="AnonVar"/>, but our dialog variable will equate
to undefined. However, our <value expr="DocumentVar"/>
scoped variable is still considered active.
</prompt>
<!--
IF WE OUTPUT THIS VARIABLE WITHIN THIS SCOPE,
WE WILL GET AN ERROR.SEMANTIC, AS THIS VAR
IS NO LONGER AVAILABLE
<log expr="DialogVar"/>
-->
<goto next="Page2.cfm"/>
</block>
</form>
</vxml>
<?xml version="1.0" encoding="UTF-8"?>
<vxml version="2.0" application="Page1.cfm">
<meta name="maintianer" content="yourEmail@here.com"/>
<form id="F1">
<block>
<prompt>
and here our <value expr="application.ApplicationVar"/> scoped
variable is available throughout the entire application. But our anonymous
scoped variable and our dialog scoped variable are no longer available.
</prompt>
<!--
IF WE OUTPUT THESE VARIABLES WITHIN THIS SCOPE,
WE WILL GET AN ERROR.SEMANTIC, AS THESE VARS
ARE NO LONGER AVAILABLE
<log expr="Anon"/>
<log expr="DialogVar"/>
-->
<log expr="DocumentVar"/>
</block>
</form>
</vxml>
| ANNOTATIONS: EXISTING POSTS |
jongmagno
|
|
| how do you assign a value to a variable from a user input? | |
mikethompson
|
|
| Hi Jong,
You can assign values to user input simply by using slot values within your grammars. I could hit you with some example code but I see a perfect example located in our GSL documentation. You can find that here: http://docs.voxeo.com/voicexml/2.0/gslmultislot.htm This will give you an in depth look at Multi-slot grammars. Hope this helps, Mike Thompson Voxeo Extreme Support |
|
appalachiangypsy
|
|
| This tutorial is awesome. I found the info I needed. Thanks. | |
bsmith
|
|
| Thank you for the feedback! We always appreciate what our customers have to say.
Thanks again, Ben Smith Voxeo Corporation |
|
SSA_MarkPMiller
|
|
| Simple typo in example code:
The second document references a non-existant root application document. The root doc is named "Page1.vxml" and the second page references 'application="Page1.cfm"' Also, the goto in the first doc references a .cfm file when it should be a .vxml file as named in the code. Mark |
|
mikethompson
|
|
| Mark,
Good catch! :) This is defintely a mix up. I imagine Matt was using .cfm for no-caching headers when he was building the application for this tutorial. I'll certainly let him know of this slip up here and have him make any changes needed. Best, Mike Thompson Voxeo Corporation |
|
sarika
|
|
| Hello,
How can i access vxml declared variable in php code or how can i access php variable in voicexml code within the same document? |
|
raghu.ram
|
|
| looking answer for thr above question.....
-rag |
|
vanguill
|
|
| Hi,
Thanks in advance for any advice you can offer. I have a vxml file, seaslugs.vxml which is functioning as my document root. In seaslugs.vxml root file, I declare a variable with application scope (appSlugColor). I gather a value for appSlugColor variable from a user inside of a slugColor field of a form getSlugInfo form within the root document. Inside of the <filled> tag corresponding to the slugColor field, I assign the value gathered from the user to the application variable appSlugColor, using <assign name="application.appColor" expr="slugColor"/>. (I've also tried this from within script tags) Immediately following that assignment, I submit a couple of values (slugColor and slugShell) to a cgi script, which looks up the slug color in a MySQL database and returns a list of slugs of that color. After retrieving the slugs from the database, the cgi writes out a new vxml file (in which seaslugs.vxml is declared as the application) which tells the user what slugs were retrieved and then then redirects the user back to another form (called goodByeSSSS) within the original application root, seaslugs.vxml, using a <goto> tag. This all works, so what's my problem? Well, it is that the value of the appSlugColor variable is lost somewhere after the post and before getting back into the form at #goodbyeSSSS. Is what I am attempting to do completely wrong, or is this a syntax or scope question? I've include the seaslugs.vxml source below. This is a learning exercise for me, so any advice will be appreciated. Thanks, Linda ---------- <?xml version="1.0"?> <vxml version="2.1" xmlns="http://www.w3.org/2001/vxml"> <property name="universals" value="help"/> <var name="myAppName" expr="'Sea Slug Survey System'" /> <var name="appSlugColor" /> <link next="#welcomeSSSS"> <grammar type="application/x-nuance-gsl" mode="voice">[main back begin]</grammar> </link> <link next="#goodbyeSSSS"> <grammar type="application/x-nuance-gsl" mode="voice">[exit quit bye goodbye]</grammar> </link> <form id="welcomeSSSS"> <block> <audio src="Welcome.wav"/> <prompt> the <value expr="application.myAppName"/>!</prompt> </block> <field name="needHelp"> <prompt>Do you require help identifying your slug?</prompt> <grammar type="application/x-nuance-gsl" mode="voice"> <![CDATA[ ;Match one of the enclosed terms [ ;Each line is recognized as a separate term ;Terms are separated by a space yes no ;Match either yes yep si or oui ;Square brackets are the same as OR [yes yep wee see] ;Parentheses require all of the enclosed terms to be matched (yes please) (no thanks) ] ]]> </grammar> <!-- The user was silent, restart the field --> <noinput> I did not hear you, please speak up. <reprompt/> </noinput> <!-- The user said something that was not defined in our grammar --> <nomatch> I do not understand those words. Please try again. <reprompt/> </nomatch> <!-- The user requested help --> <help> Please say, yes please, or, no thanks. </help> </field> <filled> <if cond="needHelp == 'yes'"> <prompt>I'm happy to help!</prompt> <goto next="#slugIdentHelp"/> <elseif cond="needHelp == 'yes please'"/> <prompt>You need polite help.</prompt> <goto next="#slugIdentHelp"/> <elseif cond="needHelp == 'no'"/> <prompt>You don't think you need help, but you will.</prompt> <goto next="#getSlugInfo"/> <elseif cond="needHelp == 'no thanks'"/> <goto next="#getSlugInfo"/> <else/> <prompt> You don't even know whether you need help. Let me tell you a few things. The caller i d number is <value expr="session.callerid"/> The called i d of this application is <say-as interpret-as="telephone"> <value expr="session.callerid"/> </say-as> </prompt> <goto next="#welcomeSSSS"/> </if> </filled> </form> <form id="slugIdentHelp"> <block><prompt>Okay. Let's walk through a few questions.</prompt></block> <field name="slugShell" slot="sShell"> <prompt> Does your slug have a shell? </prompt> <grammar type="application/x-nuance-gsl" mode="voice"> <![CDATA[[ [yes no] ]]]> </grammar> <filled> <if cond="slugShell == 'yes'"> <prompt>I'm sorry, I am not yet able to classify slugs with shells. This feature will be available in January of 2009. Returning to main menu. </prompt> <goto next="#welcomeSSSS"/> <elseif cond="slugShell == 'no'"/> <prompt> Okay then. </prompt> </if> </filled> </field> <field name="slugColor" slot="sColor"> <prompt> What color is your slug? </prompt> <grammar type="application/x-nuance-gsl" mode="voice"> <![CDATA[[ (?[light dark] [red]) { <sColor "red"> } [orange] { <sColor "orange"> } (*[light lemon] [yellow]) { <sColor "yellow"> } [green] { <sColor "green"> } [purple violet] { <sColor "purple"> } [pink fuscia] { <sColor "pink"> } [brown] { <sColor "brown"> } [white] { <sColor "white"> } (+[light dark baby royal] [blue]) { <sColor "blue"> } [black] { <sColor "black"> } ]]]> </grammar> <nomatch> I do not know that color. Please say: red, orange, yellow, green,light blue, dark blue, purple, violet, pink, brown, white, or black. <reprompt/> </nomatch> </field> <filled> <script> application.appSlugColor = 'fyoosha'; </script> <prompt> I just assigned <value expr="application.appSlugColor"/> too appSlugColor. Checking database for <value expr="slugColor$.utterance"/> slugs with index term <value expr="slugColor$.interpretation.sColor"/>. </prompt> <submit next="http://www.linguistland.net/~lcvg/cgi-bin/checkColors.cgi" namelist="slugShell slugColor" method = "get" /> <goto next="#goodbyeSSSS"/> </filled> </form> <form id="getSlugInfo"> <block><prompt>Great.</prompt></block> <field name="slugColor"> <prompt> What is the order of your slug? </prompt> <grammar type="application/x-nuance-gsl" mode="voice"> <![CDATA[[ headshield sapsucking seahare sidegill nudibranch noodibrank ]]]> </grammar> </field> </form> <form id="goodbyeSSSS"> <block> <prompt> Thank you for caring about <value expr="application.appSlugColor"/>. sea slugs. Goodbye. </prompt> </block> </form> </vxml> |
| login |
|