Information can be sent in to the server from the user either from a web form (as the questions in the survey), passed in with the web address URL or stored in a cookie. This, as well as other information about the incoming request can be retrieved using the Request object.
We will look into some of the properties of the Request object. All of these return values of the type NameValueCollection. This is a type that represents a sorted collection of associated String keys and String values that can be accessed either with the key or with the index (integer from 0). This means that their values can be referenced in the same way as you refer to values in an Array(go to About Arrays for more information), but also using their String key, for example:
var aValue = Request("arg");This will look through all values sent in with the request to find a key that matches the name specified in arg and return the corresponding value. If there is no match for arg, null will be returned. This means that you can use the expression
Request("arg")!=nullto check if it exists before using the value returned.
Note: Survey links in hitlists can have parameters added to the link. Two functions are available to receive the value from the link; Request and UserParameters (go to UserParameters for more information). The function you must use depends on the link's “Link type” setting. Request() will only be able to retrieve the value from the hitlist link when "Link type" in the Hitlist Field Properties page is set to "Unencrypted URL parameters". Refer to the separate Reportal documentation for further details.
A more robust approach than using the Request object directly is to use the separate properties of the Request object to prevent naming conflicts. In this part of the documentation we will describe some of the most useful properties.
Note: Request and Request.Form are not supported by CAPI or AskMe App. Use RequestForm instead.
Request.Form
Request.Formwill give the collection of form values submitted using "POST".
RequestForm
RequestFormThis was created because Request.Form and Request are not supported by CAPI or AskMe App. RequestForm functions in the same way as Request.Form.
QueryString
Request.QueryString()
will give the collection of values supplied on the URL or from a form submitted with GET. If you want to send values into the survey with the url, they can be included after the question mark after project_ID.aspx, separated by ampersands (&), e.g.
http://survey.confirmit.com/wix/project_ID.aspx?variable1=value1&variable2=value2
The keys here are variable1 and variable2, so using the key variable1 as in
Request.QueryString("variable1")with the url above will return the value value1.
Request Cookies
Request.Cookies
will return the cookies stored from the of the Forsta Plus server domain. It returns an HttpCookieCollection object (go to Cookies for more information).
ServerVariables
Request.ServerVariableswill give the information sent in the header or internal server values.
Here is a table listing an extract of the possible server variables in the collection returned from the ServerVariables property:
Variable |
Meaning |
| ALL_HTTP | All HTTP headers sent by the client., with their names capitalized and prefixed with HTTP_ |
| ALL_RAW | Retrieves all headers in raw form (the form they were sent to the server by the client). |
| CONTENT_LENGTH | The length of the content as given by the client. |
| CONTENT_TYPE | The MIME type of the request, such as www-url-encoded for a form being posted to the server. |
| GATEWAY_INTERFACE | The Common Gateway Interface (CGI) supported on the server. |
| HTTP_<HeaderName> | The value stored in the header HeaderName. Any header other than those listed in this table must be prefixed by HTTP_ in order for the ServerVariables collection to retrieve its value. Note that the server interprets any underscore (_) characters in HeaderName as dashes in the actual header. For example if you specify HTTP_MY_HEADER, the server searches for a header sent as MY-HEADER. |
| HTTP_ACCEPT | The MIME types the client can accept. |
| HTTP_ACCEPT_LANGUAGE | The languages accepted by the client. |
| HTTP_ACCEPT_ENCODING | The compression encoding types supported by the client. |
| HTTP_CONNECTION | Indicates whether the connection allows keep-alive functionality. |
| HTTP_COOKIE | Returns the cookie string that was included with the request. |
| HTTP_USER_AGENT | Returns a string describing the browser that sent the request. See below for an example. |
HTTP_HOST |
The host name of the server. |
HTTPS |
Returns "On" if HTTPS was used for the request and "Off" if not. |
| HTTPS_KEYSIZE | Number of bits in the encryption used to make the HTTPS connection. For example, 128. |
| HTTPS_SECRETKEYSIZE | Number of bits in server certificate private key. For example, 1024. |
| HTTPS_SERVER_ISSUER | Issuer field of the server certificate. |
| HTTPS_SERVER_SUBJECT | Subject field of the server certificate. |
| LOCAL_ADDR | The IP address of the server which is handling the request. |
| QUERY_STRING | Query information stored in the string following the question mark (?) in the HTTP request. |
| REMOTE_ADDR | The IP address of the remote host making the request. |
| REMOTE_HOST | The host name of the client making the request, if available. |
| REQUEST_METHOD | The type of the HTTP request made: "GET", "POST" or "HEAD". |
| SERVER_NAME | The server's host name, |
| SERVER_PORT | The port number to which the request was sent. |
| SERVER_PORT_SECURE | A string that contains either 0 or 1. If the request is being handled on the secure port, then this will be 1. Otherwise, it will be 0. |
| SERVER_PROTOCOL | The HTTP protocol and version in use on the server. |
| SERVER_SOFTWARE | The name and version of the web server software running on the server. |
Sending in Values with the URL
Assume you have a pop-up survey that is triggered from pop-up scripts on several sites. You want to identify which site the respondents were surfing when the pop-up appeared. In the pop-up scripts you should use different survey links for the different sites, as below:
http://survey.confirmit.com/wix/<project ID>.aspx?site=1
http://survey.confirmit.com/wix/<project ID>.aspx?site=2
http://survey.confirmit.com/wix/<project ID>.aspx?site=3
http://survey.confirmit.com/wix/<project ID>.aspx?site=4
Insert a hidden single question source in your questionnaire. The answer list should have the different sites you use and codes that correspond to the values you use in the URLs, for example:
Figure 1 - Inserting a hidden single question source
To set this hidden question based on the values sent in with the URL, use the code given below in a script node at the beginning of the questionnaire.
f("source").set(Request("site"));Alternatively, you can use the QueryString property:
f("source").set(Request.QueryString("site"));Important
The script node with Request must be the first node in the questionnaire, because once the respondent moves to the next page, the values are lost.
Now source can be used for reporting, quotas, logic etc. in the same way as an ordinary question.
Recording respondent's browser version and operating system
The system does not automatically save information about the respondent’s user agent (browser version and type and operating system (OS)) into a survey. To get this information you must add a check function into the survey at a location before your respondents start to provide answers. For this you can use the function Request.ServerVariables("HTTP_USER_AGENT"). This will contain information about the respondent application name and version and the operating system.
If you have a hidden open text question with question id UserAgent, then the script will look like this:
var agentInfo = Request.ServerVariables("HTTP_USER_AGENT");
f("UserAgent").set(agentInfo);Variable UserAgent will then contain string values that will look like this:
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36More information about the different values returned can be found here: https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx