SurveyFactory Documentation Documentation Custom redirects with response data
Custom redirects with response data

SurveyFactory now allows you to pipe a respondent's answers into redirect behaviors within your survey or completion behavior. This can be useful if you want to string multiple surveys together and pass some user-generated data from survey to survey. You can also use this behavior to pass information to a custom program on your server after the user completes a survey.

To use this feature, you should be familiar with the custom function pipeResponse and will also need to use a couple custom template filters (unescapeHTML and escape). To string surveys together, you will also need to understand how to populate a response.

Example: Redirect to Google

This is basic example to demonstrate how you can pass survey information to a third-party site or program on your own web server. The first step is to design your survey, and in this example we assume you have a Single Text Field question with an id of 2 that prompts the user for a search term. You would then add a Redirect Respondent into the completion behavior of your survey. For this example, the redirect URL you would enter is as follows:

http://www.google.com/search?q=[% pipeResponse(2) | unescapeHTML | escape %]

Now, when a user enters their search term, the survey response will be recorded on SurveyFactory and the user will be directed to Google where the response entered into the survey will be provided as their query. First, we use pipeResponse() to pull the answer from the question with an id of 2. If your questions have multiple answers, then you will need to read more about this function to retrieve the answer you are looking for. The data returned from pipeResponse() is always pre-escaped with the escapeHTML filter to prevent cross-site scripting attacks and other malicious user behavior. However, in a URL scenario, escapeHTML is not the filter we want, and instead we need to use escape that works properly on URL fragments. To keep this URL safe, you need to string unescapeHTML and then escape back to back on each parameter you pass to a redirect.

Example: Redirect and Populate Another Survey

Another advanced behavior is to string together multiple surveys. We have detailed instructions on populating all question types, but this example will cover a basic scenario of passing the user's email from one survey to the next. Assume you have both Survey A and Survey B that prompt for an email address. Each of these prompts is a Single Text Field question and on Survey A that question has an ID of 3 and on Survey B it has an ID of 5. To pass data from the first survey to the second, and redirect the user there upon completion, you would set a redirect with the following in the completion behavior of Survey A:

http://surveyfactory.net/s/000/mysurvey?q5=[% pipeResponse(3) | unescapeHTML | escape %]

If you need any help with more complicated examples, please submit a support request and we will be happy to help.