SoSci Survey enables the user to make content (e.g. questions or items) variable. In order to do so, placeholders are integrated in the form %placeholder%. Something will then be inserted in the questionnaire as the placeholder – for example, the participant's response to a previous question, randomly selected content/stimulus or the result of a live analysis.
There are three types of placeholders:
Note: User-defined placeholders do not work on the “last page” of a questionnaire, because background data is removed from the case when the interview is completed (FINISHED=1). If necessary, create an additional second-to-last page with buttonHide().
Tip: Placeholders work in practically all forms of text: from the question itself to items, text elements, HTML code and so on.
Tip: If a user-defined placeholder is set up initially with replace(), it can then be used in all the following pages of the questionnaire.
If you use the following example as a text element in the questionnaire, the serial number of the questionnaire (predefined placeholder %caseNumber%) will be displayed.
The number of your questionnaire is %caseNumber%. Please quote this number if you would like an analysis of your data.
User-defined placeholders are set up with the replace() function.
replace('%vehicle%', 'AB01', 'response'); // make the answer from AB01 the %vehicle% placeholder
You stated earlier that you mostly travel to work by %vehicle%.
In addition, there are some predefined placeholders (see below) and the possibility to freely place input fields (from other questions) using placeholders.
The following example demonstrates how placeholders can be combined with conditional questions.
In question SD01 the participant's gender is prompted. In other questions, information should be collected as to how the participant responds to people of the opposite gender. To do this, a placeholder %person% is set up and is replaced in the questionnaire by either “a man” or “a woman”. A second placeholder %people% is set up with the plural form.
The following PHP code is placed on the page after question SD01.
if (value('SD01') == 1) { // respondent is a woman replace('%person%', 'a man'); replace('%people%', 'men'); } elseif (value('SD01') == 2) { replace('%person%', 'a woman'); replace('%people%', 'women'); }
The placeholders %person% and %people% can now be used in other questions (also on the same page; below the PHP code).
What are the most important characteristics %person% must possess in order to take on a leadership role?
Moving on to your experiences: how do you think %people% usually act in a crisis?
The following placeholders are automatically available; these IDs must not be used for user-defined placeholders. The contents of some placeholders can also be retrieved by a PHP function for further use (right column).
| Placeholder | Description | Variable in Data | PHP Function |
|---|---|---|---|
%caseLanguage% | Language of the ongoing interview [language code] | LANGUAGE | getLanguage() |
%caseNumber% | Serial number of the interview | CASE | caseNumber() |
%caseSerial% | Participation code or personal ID of the interview | SERIAL | caseSerial() |
%caseToken% | Internal ID of the interview | - | caseToken() |
%reference% | Reference that was passed to the questionnaire | REF | reference() |
%pageNumber.abs% | Number of the current page according to Compose Questionnaire (be careful when using filter questions) | ||
%pageNumber.cnt% | Number of the page according to Compose Questionnaire from which the content of the page originates – same as %pageNumber.abs% as long as no goToPage() is used to jump to another page and a question or other content was displayed there. |
||
%pageNumber.rel% | Number of the current page counted since the beginning of the interview (not compatible with goToQuestionnaire(), multiLevelDown() and the function Collected Data → Restart an Interview Case) |
||
%lang.label% | Name of the active language version (e.g. “English”) | ||
%lang.short% | 2-letter abbreviation of the active language version (e.g. “EN”) | ||
%year% | 4-digit year (for example, for use in the footer) | date('Y') |
|
The following placeholders are available within items or options (e.g. in the item text). The numbering helps, e.g., to number randomly rotated options consecutively.
| Placeholder | Description | Example |
|---|---|---|
%i.n.% | Number of the item followed by a period and a space | 1. |
%i.a)% | Number of the item followed by a bracket (lower case letter) | a) |
%i.num% | Number of the item within the question (numeric) | 1 |
%i.num.a% | Number of the item within the question (lower case letter) | a |
%i.num.A% | Number of the item within the question (upper case letter) | A |
%i.cnt% | Number of items within the question | 5 |
The following placeholders are available in some (not yet all) error messages, which can be customized under Text Elements and Labels. If the affected question has no number, the placeholder is left blank (removed).
| Placeholder | Description | Example | Example |
|---|---|---|---|
%q.desc% | Description of the question(s) concerned | question 1 | questions 2,3 |
%(q.desc)% | Description in brackets | (question 1) | (questions 2,3) |
%q.list% | Number(s) of the question(s) concerned | 1 | 2,3 |
The following placeholders are designated exclusively for use in the HTML template of a layout. Further placeholders for the layout are documented under Questionnaire Layouts: Full Customization.
| Placeholder | Description |
|---|---|
%logo% | HTML code for the active logo |
%imprint% | HTML code for the footer/contact information |
%progress% | HTML code for the progress bar |
%head%\ <link type="placeholder" href="head"> | HTML code for the header in the layout template\ (HTML compliant variant) |
%questionnaire% | HTML code for the content in the layout template |
If you are using customized placeholders, please take the following ID requirements into consideration:
%) (no spaces, no number).%…%).%plc%) and%person% is a different placeholder to %Person%.In the following examples each placeholder ID is shown in brackets:
In order to use placeholders efficiently, basic knowledge of PHP programming (PHP Code and experience with variables) is required.
In the following example one of three possible brands (code 1, 2 or 3) is selected from an urn (Randomization Using Urns). After this, a placeholder is employed to use the brand directly in the question title.
// First of all, different brands are saved in an array $brands = array( 1 => 'Ammerseebach', 2 => 'Britentyler', 3 => 'Changuella' ); // One of these brands is chosen at random urnDraw('urn', 'IV01'); $code = value('IV01_01'); // the label name of the brand is read from the array above with the code (1-3) // (you could also use a filter here instead of the array) $brand = $brands[$code]; // the name of the brand is now stored in the placeholder %brand% replace('%brand%', $brand);
The question title and items are set up as follows:
"Please evaluate the following statements in light of %brand%!" Item 1: "I find %brand% better than SoSci Survey" Item 2: "%brand% looks more artificial"
It is fairly simple to follow up on a participant's answer later on in the questionnaire by using placeholders. You just have to be careful to ensure that the questionnaire continues to work correctly if the participant fails to answer the question (or only inputs blank spaces).
The prerequisite for the following example is that a brand name is prompted in the open text field TX01_01. The following PHP code cannot be put on the same page as the question TX01, but must be put on one of the following pages instead.
// read participant's answer $brand = value('TX01_01'); // remove blank spaces $brand = trim($brand); // respond appropriately if no answer is given if ($brand == '') { goToPage('next'); // go to next page } // set up placeholder %brand% replace('%brand%', $brand); // following questions can now use the placeholder %brand%
If item TX01_01 is a compulsory question and therefore has to be answered (i.e. there can be no missing answer), then replace() can call up the answer directly.
// prepare placeholder %brand% replace('%brand%', 'TX01_01', 'response'); // following questions can now use the placeholder %brand%
In the following example, the option which was selected in a selection (single choice or drop-down) should be displayed as text. The prerequisite here was that a type of fruit be chosen in the selection question AU01.
Once again, due to the value(), the PHP code cannot be on the same page as the AU01 question, but must be put on one of the following pages instead.
Tip: Please also read the value() function manual.
// first of all, check that something has been selected if (value('AU01') < 0) { // go to next page goToPage('next'); } // read answer - observe the second parameter 'text' $text = value('AU01', 'text'); // set up placeholder %fruit% replace('%fruit%', $text); // following questions or text can now use the %fruit% placeholder.
replace() also calls up the value directly if AU01 is a compulsory question and therefore a filter would be unnecessary:
// set up placeholder %fruit% replace('%fruit%', 'AU01', 'response'); // following questions or text can now use the %fruit% placeholder.