Mod_Survey Syntax Reference

3.2.x branch

MSc. Joel Palmius

Mid Sweden University
Department of Information Technology and Media

This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.


Table of Contents
1. Introduction
Tags
Markup
Includes
Snippets
2. Configuration tags
SURVEY
MAILCOPY
SECURITY
3. Visible variable-carrying tags
BOOLEAN
CHOICE
CUSTOM
LICKERT
LIST
MATRIX
MEMO
TEXT
4. Invisible variable-carrying tags
CONSTANT
DATETIME
ENV
IMPORT
TIMER
5. Tags related to multipaging
CASEROUTE
IFROUTE
RANDOMROUTE
ROUTE
SEQUENCE
6. Layout-related and other tags
NEWLINE
COMMENT
7. Extra HTML markup
Color
Font styles
Graphics
Special
Custom HTML markup
8. Dynamic content
Including external files
Referencing previous variables
Session variables
Perl snippets
List of Tables
2-1. SURVEY parameter reference
2-2. MAILCOPY parameter reference
2-3. SECURITY parameter reference
2-4. Subtags of SECURITY ("security domains")
2-5. LEVEL settings
2-6. ANSWER parameter reference
2-7. DATA parameter reference
2-8. DEBUG parameter reference
2-9. FLUSH parameter reference
2-10. SOURCE parameter reference
3-1. BOOLEAN parameter reference
3-2. CHOICE parameter reference
3-3. CHOICEELEMENT parameter reference
3-4. DBCHOICEELEMENT parameter reference
3-5. CUSTOM parameter reference
3-6. LICKERT parameter reference
3-7. LIST parameter reference
3-8. LISTELEMENT parameter reference
3-9. DBLISTELEMENT parameter reference
3-10. MATRIX parameter reference
3-11. MATRIXCOLUMN parameter reference
3-12. MATRIXROW parameter reference
3-13. MEMO parameter reference
3-14. TEXT parameter reference
4-1. CONSTANT parameter reference
4-2. DATETIME parameter reference
4-3. FORMAT codes
4-4. ENV parameter reference
4-5. Examples of environment variables
4-6. IMPORT parameter reference
4-7. VARIABLE parameter reference
4-8. FILTER parameter reference
4-9. ARRAY parameter reference
4-10. TIMER parameter reference
5-1. CASEROUTE parameter reference
5-2. CASE parameter reference
5-3. IFROUTE parameter reference
5-4. IF parameter reference
5-5. Boolean conditions
5-6. Boolean condition parameter reference
5-7. RANDOMROUTE parameter reference
5-8. ALTERNATIVE parameter reference
5-9. ROUTE parameter reference
5-10. SEQUENCE parameter reference
5-11. FILENAME parameter reference
6-1. NEWLINE parameter reference
6-2. COMMENT parameter reference

Chapter 1. Introduction

This manual summarizes the syntax of the survey language in the 3.2.x branch. For an overview of what has changed since the 3.0.x branch, please refer to "Mod_Survey for Beginners".

Note that the following material presupposes an understanding of the basics of Mod_Survey. For an introduction on how survey files are written, and a step-by-step tutorial on the survey language, refer to "Mod_Survey for Beginners".


Tags

The majority of the survey language consists of an XML-based set of "tags". These are written in the style common to HTML, XML and SGML. Most of the tags define variables (usually questions), but there are also tags related to page routing and configuration.

In the reference, a name of an optional parameter is written as PARAMETER, while a required parameter is written as PARAMETER.

In the following text an "open" tag will denote a tag which have contents apart from its parameters, and is written in the form TAG PARAMETERS...(contents)/TAG. A "closed" tag does not have any contents apart from its parameters, and must be immediately terminated in the form TAG PARAMETERS... /.


Markup

Apart from the tags, there is also a set of specific codes used to modify the HTML output. These are in the form {code}...{/code}. They are used, for example, to boldface a word in a caption. The extra markup can be used in all places in the code that end up as visible output. Examples are in the CAPTION parameter of a question or inside a CUSTOM block.


Includes

The SURVEY markup allows linking to external files during different phases of the survey's life span: they can be included before or after syntax parsing. This can be used, for example, to include one common set of questions into many surveys, or to keep large blocks of HTML code outside the definition of questions.


Snippets

Finally, there are perl "snippets". This is perl code which can be inserted in the survey and execute during various instances of the survey life span. Examples could be for producing a large MATRIX from an array of values. The perl snippets are fed through the "Safe" module and will not allow any interaction with the file system.


Chapter 2. Configuration tags


SURVEY

The SURVEY tag is the top-level container of the survey. All other data is contained within the SURVEY tag. The survey tag is always open.

Table 2-1. SURVEY parameter reference


MAILCOPY

The MAILCOPY tag specifies that an email containing the data submitted by the latest respondent should be sent to a specified email address. While this tag is possible to place anywhere in a multipage chain, it makes most sense to place it in the last page.

Note that configuration of default email address and SMTP host takes place in survey.conf and thus isn't possible to change by the user.

Table 2-2. MAILCOPY parameter reference


SECURITY

The SECURITY tag and its subtags specifies how access should be permitted (or not permitted) to security domains of the survey.

Table 2-3. SECURITY parameter reference

The SECURITY tag is open and may contain the following subtags:

Table 2-4. Subtags of SECURITY ("security domains")

All security tags have a LEVEL parameter used to restrict or open access to the security domain.

Table 2-5. LEVEL settings

Table 2-6. ANSWER parameter reference

Table 2-7. DATA parameter reference

Table 2-8. DEBUG parameter reference

Table 2-9. FLUSH parameter reference

Table 2-10. SOURCE parameter reference


Chapter 3. Visible variable-carrying tags


BOOLEAN

The BOOLEAN tag specifies an on/off checkbox kind of style question. The BOOLEAN tag is always closed.

Table 3-1. BOOLEAN parameter reference


CHOICE

The CHOICE tag specifies an array of possible options. The user may be single choice or multiple choice depending on the state of the MULTIPLE parameter (see below). The CHOICE tag is always open and must contain at least one CHOICEELEMENT.

Table 3-2. CHOICE parameter reference

The CHOICEELEMENT subtag of the CHOICE tag represent one respondent-selectable answer to the object's question.

Table 3-3. CHOICEELEMENT parameter reference

The DBCHOICEELEMENT subtag of the CHOICE tag represents an array of possible answers. The array(s) must have been either imported via the IMPORT tag, or created in a perl snippet.

Table 3-4. DBCHOICEELEMENT parameter reference


CUSTOM

The CUSTOM tag specifies one or more objects, visually designed by the author of the survey. The CUSTOM tag is always open and contains HTML code.

Note that the CUSTOM tag can also be used to insert any HTML data into the survey. It does not necessarily have to specify a variable. Whether it does is specified by the VARIABLES parameter.

Table 3-5. CUSTOM parameter reference

Explanation of escaped. To be written.


LICKERT

The LICKERT tag specifies a scale with discreet values ranging between two opposites. The default function is to range with five steps between "true" and "false". The LICKERT tag is always closed.

Table 3-6. LICKERT parameter reference


LIST

The LIST tag specifies a list of string from which the respondent can choose one. The LIST tag may be presented so that only a few of the strings are displayed at a time (so that the respondent has to scroll to view more of the list). A LIST tag is always open and must contain at least one LISTELEMENT.

Table 3-7. LIST parameter reference

The LISTELEMENT subtag of the LIST tag represent one respondent-selectable answer to the object's question.

Table 3-8. LISTELEMENT parameter reference

The DBLISTELEMENT subtag of the LIST tag represents an array of possible answers. The array(s) must have been either imported via the IMPORT tag, or created in a perl snippet.

Table 3-9. DBLISTELEMENT parameter reference


MATRIX

The MATRIX tag specifies an array of variables, each of which can take a single- or multiselect answer. The MATRIX consists of MATRIXCOLUMN and MATRIXROW tags, which defines the possible answers to all the questions in the array, and the questions themselves. Depending on the settings of the UNIQUECOLUMNS and UNIQUEROWS parameters, either the rows or the columns will be chosen as being the axis carrying the variables.

Table 3-10. MATRIX parameter reference

The MATRIXCOLUMN defines a column in the MATRIX. In MATRIX's default mode of operation, this is a possible answer to a question defined in a MATRIXROW. A MATRIX block must contain at least one MATRIXCOLUMN.

Table 3-11. MATRIXCOLUMN parameter reference

The MATRIXROW defines a row in the MATRIX. In MATRIX's default mode of operation, this is a question, with its possible answers defined by MATRIXCOLUMNs. A MATRIX block must contain at least one MATRIXROW.

Table 3-12. MATRIXROW parameter reference


MEMO

The MEMO tag specifies an open answer multi-line text field.

Table 3-13. MEMO parameter reference


TEXT

The TEXT tag specifies an open free-text one line field. The field can be limited to only accepting numerical values within a range. The TEXT tag is always closed.

Table 3-14. TEXT parameter reference


Chapter 4. Invisible variable-carrying tags


CONSTANT

The CONSTANT tag specifies a constant value, which is not affected in any way by the user. This could, for example, be the revision of the questionnaire. The CONSTANT tag is always closed.

Table 4-1. CONSTANT parameter reference


DATETIME

The DATETIME tag represents a time and/or datestamp of the moment when the respondent submitted his answers. The actual contents of the stamp is set in the FORMAT parameter. The DATETIME tag is always closed.

Table 4-2. DATETIME parameter reference

The FORMAT parameter contains character codes representing different parts of a date/time stamp.

Table 4-3. FORMAT codes

#Yfour-digit year2003
#Mtwo-digit month04
#Dtwo-digit day of month05
#dthree-digit day of year290
#aabbrev month name"feb"
#Afull month name"february"
#wabbrev weekday name"tue"
#Wfull weekday name"tuesday"
#htwo-digit hour (24)23
#mtwo-digit minute15
#stwo-digit second20
#eseconds since epoch1066464551

ENV

The ENV tag fetches a value from the environment, such as the respondent's IP number, or the server's apache version. The ENV tag is always closed.

Table 4-4. ENV parameter reference

There is no restriction in which environment variables that can be read. This is completely dependent on which variables are set by the server. Thus, there is no way to list all possible variables here. However, there are a number of common variable names which are often used in web server environments.

Table 4-5. Examples of environment variables


IMPORT

The IMPORT tag fetches one or more variables/values from a database table and inserts them into the survey as if they had been submitted by the user. The IMPORTed variables are treated as any other variables and are thus possible to use for routing and in dynamic markup.

The IMPORT tag can contain one FILTER subtag and must contain at least one VARIABLE subtag.

Table 4-6. IMPORT parameter reference

Each VARIABLE subtag defines a variable fetched from a field in the database table specified in the IMPORT tag.

Table 4-7. VARIABLE parameter reference

The FILTER subtag defines the criteria for narrowing the selection from the database table specified in the IMPORT tag. If no FILTER tag is specified, the first record in the table will be used.

Note that you can use the dynamic markup in the FILTER parameters. Thus, it's perfectly OK to say CRITERIA="userid={$uid$}" if "uid" was, say, a TEXT occurring earlier in the survey chain.

Table 4-8. FILTER parameter reference

Each ARRAY subtag constructs a new array from all the values of a table column.

Table 4-9. ARRAY parameter reference


TIMER

The TIMER tag represents the time (in seconds) it took for the respondent to answer the survey (in practise time from load to submit). The TIMER tag is always closed.

Table 4-10. TIMER parameter reference


Chapter 5. Tags related to multipaging


CASEROUTE

The CASEROUTE defines a conditional branching depending on the value of one previously submitted value. The CASROUTE basically consists of a SWITCH parameter telling which variable to evaluate, and a number of CASE subtags defining possible values and routes.

Table 5-1. CASEROUTE parameter reference

The CASEROUTE tag must contain at least one CASE tag.

Table 5-2. CASE parameter reference


IFROUTE

The IFROUTE defines a conditional branching dependent on one or more boolean conditions, such as whether a variable value is less than a certain constant. The IFROUTE tag contains IF subtags, each of which defines a condition by in its turn containing a list of boolean conditions (see below).

Table 5-3. IFROUTE parameter reference

The IFROUTE tag must contain at least one IF subtag.

Table 5-4. IF parameter reference

Each IF tag must contain at least one of the following subtags:

Table 5-5. Boolean conditions

All boolean condition tags have the following parameters.

Table 5-6. Boolean condition parameter reference


RANDOMROUTE

The RANDOMROUTE defines a conditional branching where the next page is randomly picked from a list.

Table 5-7. RANDOMROUTE parameter reference

The RANDOMROUTE tag must contain at least one ALTERNATIVE tag.

Table 5-8. ALTERNATIVE parameter reference


ROUTE

The ROUTE tag defines an unconditional route. This should not be confused with the CONTINUE parameter in the SURVEY tag. By using the ROUTE tag, one sends the respondent to the next page in a survey containing several pages. With SURVEY's CONTINUE, the respondent is sent to a page outside the survey.

Table 5-9. ROUTE parameter reference


SEQUENCE

When having written a survey with more than one page, the last page must contain a SEQUENCE tag, listing all the pages that were contained in the survey. This should also include pages that the user did not see because of having been routed past them. The SEQUENCE tag must contain at least one FILE subtag.

When finally submitting or downloading data, it is the SEQUENCE tag which tells the system which pages (and in consequence variables) to include.

Table 5-10. SEQUENCE parameter reference

The SEQUENCE tag must contain at least one FILE subtag. Each FILE subtag points to one of the pages that were contained in the survey. Filenames may be absolute or relative, but may not be URLs.

Table 5-11. FILENAME parameter reference


Chapter 6. Layout-related and other tags


NEWLINE

The NEWLINE tag inserts one or more linefeeds in the visible output. This is usually used to get more space between question objects. See also the SURVEY tag's AUTONEWLINES parameter. The NEWLINE tag is always closed.

Table 6-1. NEWLINE parameter reference


COMMENT

The COMMENT tag usually does nothing. It is available as a support for the author of the survey, so he can insert notes of his own in the survey file. The COMMENT tag is always open and may contain any text.

Table 6-2. COMMENT parameter reference


Chapter 7. Extra HTML markup

This chapter specifies the codes used for inserting extra HTML code in the survey output. This can, for example, be used for changing colors or boldfacing text.

Note that this markup is in development and may change slightly during the versions to come. Further, it can be expected to be occasionally somewhat buggy.


Color

Color codes can be inserted in any visible output, such as in a question's CAPTION parameter. It is the used in the form "This is some {red}amusingly colored{/red} text". With this example "amusingly colored" would be red while the rest of the text would have the default text color (see the TEXTCOLOR parameter of the SURVEY tag).

The following color codes are defined:

{red}{/red} {green}{/green} {blue}{/blue} {yellow}{/yellow} {purple}{/purple} {cyan}{/cyan} {black}{/black} {white}{/white}

Other colors can be defined manually using the custom HTML markup.


Font styles

Font styles can be inserted in any visible output, such as in a question's CAPTION parameter. It is the used in the form "This is some {i}emphasized{/i} text". With this example "emphasized" would be in italics while the rest of the text would be plain.

The following style codes are defined:

{b}{/b}(boldface) {i}{/i}(italics) {u}{/u}(underline)

Graphics

The currently only graphics-related special markup is one used for pasting images in visual output. By writing, for example, CAPTION="{image}happyface.jpg{/image}", the image "happyface.jpg" would appear where the caption text would normally be.


Special

Special characters can be inserted in any visible output, such as in a question's CAPTION parameter. A special character is a character which does not mix well with XML syntax, and which therefore have to be coded. Examples of such characters are " and .

An example would be hving the following CAPTION: "I think x {[} y", which would be printed as "I think x y".

The following special characters are defined:

{-}=(insert an equal mark) {:};(insert a semi-colon) {'}"(insert a citation mark) {[}(insert a "less than") {]}(insert a "more than") {A}(insert an ampersand)

Custom HTML markup

By using the special character markup, it is possible to insert any HTML code in the output. It is possible, but somewhat cumbersome. For example, inserting a br in a TEXT's CAPTION would look like this:

TEXT NAME="test" CAPTION="Line 1{[}br{]}Line 2" /

In other words, one has to insert the special escape codes for the parts of the HTML markup.


Chapter 8. Dynamic content


Including external files

External files may be included into the survey at two different stages during the survey' life cycle. The first is before parse. This causes the contents of the linked file to be parsed as if it was a part of the survey code. The second is after parse, in which case the contents will simply be pasted verbatim into the visual output.

{@filename@}(Include "filename" before parse) {¤filename¤}(Include "filename" after parse)

The before parse link can be inserted anywhere in the survey file. The after parse link can only be inserted in visual output, such as in a CUSTOM block or in a CAPTION.


Referencing previous variables

References to variable answers submitted on an earlier page can be inserted in all visible output, such as in a question's CAPTION. The types of references available are:

{$variable$}(Insert variable as-is) {%variable%}(Insert caption corresponding to variable value) {!variable/n1:output,n2:output...!}(Selection, choose output depending on variable value)

For example, an as-is insertion could be:

TEXT NAME="test1" CAPTION="How old are you, {$respname$}?" /

.. which would result in, for example, the caption "How old are you, Joel?"

Suppose a previous page contained a CHOICE listing possible fruits. A caption insertion example could then be:

LICKERT NAME="test2" CAPTION="Do you want a {%fruitsel%}?" /

.. which would result in, for example, the caption "Do you want a banana?"

Suppose a previous page contained a CHOICE for selecting respondent gender. A selection insertion could then be:

TEXT NAME="test3" CAPTION="What is your name, {!gender/0:boy,1:girl!}?" /

.. which would result in, for example, the caption "What is your name, boy?"


Session variables

Session variables can be referenced via {_[name]_}. A session variable do not necessarily have any connection to a question object, and some knowledge of the internals of Mod_Survey will be required to actually have some use of this feature.


Perl snippets

Perl snippets allows executable code to be inserted into the survey without voiding the system security. This is possible since all the included perl code is passed through the Safe module, which denies all forms of system access.

Snippet blocks are executed either before parse, after parse or submit time. Thus a snippet can be used to produce survey code. If printed as {..}, it will be executed before parse, if {\..\} after parse and if {|..|} at submit time. Snippets executed after parse can only be inserted into visible output, such as CUSTOM blocks or CAPTIONs, wherease snippets executed before parse can be put anywhere in the code. Submit-time perl can only be placed within the SUBMIT tag.

  { .. code to execute before parse .. }
  {\ .. code to execute after parse .. \}
  {| .. code to execute submit time .. |}