Reputation: 933
I have a single page VXML Script, I have passed dialed DTMF to a form and that works fine.
But I would also like to pass the value into a PHP Variable.
Is that possible ?
<prompt> <value expr="Digits"/> </prompt>
This works but how to I assign 'Digits' to $test in PHP ?
Thanks
Upvotes: 0
Views: 2435
Reputation: 56
In VoiceXML the process of passing variables into a server side script is commonly done using one of three tags (<submit>
, <subdialog>
or <data>
). All three of these support a standard convention of providing a URL, HTTP method (get or post) and a namelist of variables that will be sent to the web server.
Assuming you have a fairly simple VoiceXML script:
<?xml version="1.0"?>
<vxml version="2.1">
<form>
<field name="Digits" type="digits">
<prompt>Please enter some digits.</prompt>
<filled>
<prompt>You entered: <value expr="Digits"/></prompt>
<submit next="path/to/script.php" method="post" namelist="Digits"/>
</filled>
</field>
</form>
</vxml>
You would then access the variables in VoiceXML using the normal $_POST variable:
<?php
$test = $_POST['Digits'];
echo("<?vxml version=\"1.0\"?>\n");
?>
<vxml version="2.1">
<form>
<block>
<prompt>You posted: <?=htmlspecialchars($test)?>.</prompt>
</block>
</form>
</vxml>
This architecture allows VoiceXML to operate is a traditional web server / web browser with HTTP POST and response. You can also use the <data>
tag to more closely mimic modern AJAX style applications where you can POST name/value pairs and get back arbitrary XML documents that can be accessed using the normal Javascript DOM.
Upvotes: 2