Community Documentation

Handling script variables

Last updated March 19, 2011. Created by leoburd on March 2, 2011.
Log in to edit this page.

Most VoipScript commands receive parameters as input and set script variables as output.

For instance, the command "get input" receives, among other parameters, a "prompt" to be played to the user. After it is executed, the "get input" command sets the script variable input_digits with the digits typed in.

$prompt = 'Please type your zip code after the beep';
$script->addGetInput($prompt);
$script->addSay("You typed %input_digits");

In the example above, note the % symbol in the string passed to the "say" command. Whenever VoIP Drupal finds the % symbol in a string, it tries to replace it by the contents of the script variable whose name immediately follows that symbol.

Similarly, using the t() function to translate the parameter strings:

$prompt = 'Please type your zip code after the beep';
$script->addGetInput($prompt);
$args = array('@input' => '%input_digits');
$script->addSay(t("You typed @input", $args));

The "set" command can be used to store values in script variables. For instance, in the code below

global $user;
$script->addSet('name', $user->name);
$script->addSet('password', '%input_digits');

the variable "name" will be set to the user's name, whereas the variable "password" will be set to the contents of "input_digits".

Script variables are created during the first time that they are "set". In order to remove them, use the "unset" command:

$script->addUnset('name');
$script->addUnset('password');

Site Building Guide

Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here