Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
en:create:transfer-responses [01.04.2016 15:44]
admin Formatting
en:create:transfer-responses [29.04.2021 20:43]
sophia.schauer
Line 1: Line 1:
-====== Insert Answer Texts in Follow-up Questions ======+====== Show Answers in Follow-up Question ======
  
-[[::en:create:Placeholders|Placeholders]] allow you to use participants‘ text inputs elsewhere in the questionnaire. This chapter provides you with a number of examples.+[[:en:create:Placeholders|Placeholders]] allow you to use participants‘ text inputs elsewhere in the questionnaire. This chapter provides you with a number of examples (also known as "piping"). 
 + 
 +**Example:** At the beginning of the questionnaire, the participant selects which online network he personally uses most often. In later questions, the name of the network (e.g., "diaspora*") should then appear in question and item texts (e.g., "How often do you use diaspora* on a usual workday?")
    
 **Note:** If in a follow-up question you only want to display specific scale items or select options dependent on the participant’s response, please refer to [[:en:create:filter-items]]. **Note:** If in a follow-up question you only want to display specific scale items or select options dependent on the participant’s response, please refer to [[:en:create:filter-items]].
Line 8: Line 10:
  
  
-===== Use Single Answers =====+===== Use Open Text Answers =====
  
 On page 2 the participant mentioned the name of a TV presenter in a text input field (tagging ''TX01_01''). Answer validation was applied to ensure the participant did enter something. The entered name is now to be included in following question texts or scale items.  On page 2 the participant mentioned the name of a TV presenter in a text input field (tagging ''TX01_01''). Answer validation was applied to ensure the participant did enter something. The entered name is now to be included in following question texts or scale items. 
Line 38: Line 40:
 replace('%presenter%', $name); replace('%presenter%', $name);
 </code> </code>
 +
 +===== Use Closed Answers =====
 +
 +The use of closed responses works in the same way as open responses.
 +
 +The following example assumes that in choice question ''SN01'' the participant selected the online network he or she uses most often. The following PHP code (placed on the following page or later) ensures that the placeholder ''%sns%'' is subsequently always replaced by the name of the selected network.
 +
 +<code php>
 +replace('%sns%', 'SN01', 'response');
 +</code>
 +
 +If one were to read the response to ''SN01'' using ''[[:en:create:functions:value]]'', one would first get the numeric response code. If you want to read the text of the response option for further processing, you can either use the command ''[[:en:create:functions:getitemtext]]'' -- or much simpler -- specify '''label''' as the second parameter in ''value()''.
 +
 +<code php>
 +$answer = value('SN01', 'label');
 +html('<h1>'.$answer.'</h1>');
 +</code>
 +
 +Multiple choise questions are a spezial case. Here you can either look at the individual selection options (each is represented by its own variable, cf. **Variables overview**) or the entire question.
 +
 +  * The command ''value('MA01')'' applied to the multiple selection ''MA01'' does not (!) return the code of the first selected option, but the number of selected (non-exclusive) options.
 +  * The command ''value('MA01', 'label')'' returns a comma-separated list of the selected options. The same applies to the use of ''replace('%placeholder%', 'MA01', 'response')''..
 +
 +===== "Other" Input Fields =====
 +
 +If one uses a choice question with an open residual category "Other: %%___%%", then ''replace('%sns%', 'SN01', 'response')'' continues to work. If the participant chooses one of the given selection options, the placeholder will be replaced by it. If he chooses a selection option with an open input field, the placeholder is replaced by the participant's text input.
 +
 +<code php>
 +replace('%sns%', 'SN01', 'response');
 +</code>
 +
 +The function ''value()'' is a bit more strict. ''value('SN01', 'label')'' returns the text "Other:". If, on the other hand, you specify '''free''' as the third parameter (''value('SN01', 'free')''), you get either the selected option or -- if an option with an open input field was selected -- the participant's open input.
 +
 +
  
 ===== Insert Several Answer Texts ===== ===== Insert Several Answer Texts =====
Line 64: Line 100:
 Via ''[[:en:create:functions:value]]'' the following PHP code reads out all of  the ten possible text input fields, checks if an entry has been made, creates the placeholders ''%text1%'' to ''%text10%'' and displays question FQ01 with the matching items/options. Via ''[[:en:create:functions:value]]'' the following PHP code reads out all of  the ten possible text input fields, checks if an entry has been made, creates the placeholders ''%text1%'' to ''%text10%'' and displays question FQ01 with the matching items/options.
  
-**Important:** The PHP codes for “Text Input“ and “Free Mention” differ slightly in line 4, because the variables are determined according to different patterns (''TX01_01'' vs. ''TX02x01''). +<code php>
- +
-^Text Input^Free Mentions^ +
-|<code php>+
 $question = 'TX01'; $question = 'TX01';
 $items = array(); $items = array();
 for ($i=1; $i<=10; $i++) { for ($i=1; $i<=10; $i++) {
-  $itemID = $question.'_'.sprintf('%02d', $i);+  $itemID = id($question, $i);
   $answer = value($itemID);   $answer = value($itemID);
   if (trim($answer) != '') {   if (trim($answer) != '') {
Line 78: Line 111:
   }   }
 } }
-// Folgefrage anzeigen+// show follow up question
 if (count($items) > 0) { if (count($items) > 0) {
   question('FF01', $items);   question('FF01', $items);
 } }
-</code>|<code php> +</code>
-$question = 'TX02'; +
-$items = array(); +
-for ($i=1; $i<=10; $i++) { +
-  $itemID = $question.'x'.sprintf('%02d', $i); +
-  $answer = value($itemID); +
-  if (trim($answer) != '') { +
-    replace('%text'.$i.'%', $answer); +
-    $items[] = $i; +
-  } +
-+
-// Folgefrage anzeigen +
-if (count($items) > 0) { +
-  question('FF01', $items); +
-+
-</code>|+
  
 Explanatory note on the PHP code: The IF filter at the end ensures that the follow-up question is skipped if the participant has not completed the relevant field. Through ''trim()'' blank spaces at the beginning and end of the text entered are removed so that a number of blanks entered into a text field are not interpreted as a valid answer.  Through ''sprintf()'' with its parameter '''%02d''' it is ensured that numbers are displayed as double-digits with leading zeros (e. g. ''01'' instead of ''1''). Explanatory note on the PHP code: The IF filter at the end ensures that the follow-up question is skipped if the participant has not completed the relevant field. Through ''trim()'' blank spaces at the beginning and end of the text entered are removed so that a number of blanks entered into a text field are not interpreted as a valid answer.  Through ''sprintf()'' with its parameter '''%02d''' it is ensured that numbers are displayed as double-digits with leading zeros (e. g. ''01'' instead of ''1'').
en/create/transfer-responses.txt · Last modified: 29.04.2021 20:43 by sophia.schauer
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki