[[preset()]]
Translations of this page:
 

Table of Contents

preset()

void preset(string variable, int|string code)

An answer option can be preselected with the function preset(). Text can also be specified as an answer for text input questions.

  • variable
    The ID of the variable belonging to the input field. You can find the the correct variable ID in the Variables Overview.
  • code
    For closed questions, the (numeric) answer code; for open questions, the text that should be preset.
    • You can find the codes for the selection options for selections, scales, … in the Variables Overview (please see Encoding and Output Values).
    • Text must be written in quotation marks.

Tips

Note: preset() must be used on the same page as the question for which an answer should be specified.

Note: preset() must be called before (above) the question, for which the preset should apply.

Note: For a simple selection, the variable ID corresponds to the question ID. The ID of option to be selected is to be given as the value.

Note: If an option is preselected for a drop-down selection, the questionnaire does not display the default option “[Please select]”. Add a fallback option (“don't know”) in the question.

Tip: You can also preset text for free input fields in a (multiple-choice) selection (Free Text Inputs Within a Selection). Use the exact variable ID for this, as can be read in the Variables Overview.

Examples

In a multiple-choice selection “MF01”, the first and second options should be preselected. The following PHP code must be placed before/above the question.

preset('MF01_01',2);
preset('MF01_04',2);

In the selection “EA01”, the third option should be preselected.

preset('EA01', 3);

The slider with the ID “SR01_01” with a differentiation ranging from 1 to 101 should be preset to 50% (valye:51).

preset('SR01_01', 51);

The text “n/s” (not specified) should be preset for the free text input “TE01_01”:

preset('TE01_01', 'n/s');

In a question battery “SB01” with 20 scale items, the first option shall be pre-selected. Instead of typing 20 preset() commands, a FOREACH loop can be used.

$items = getItems('SB01', 'all');
foreach ($items as $item) {
  $itemID = 'SB01_'.sprintf('%02d', $item);
  preset($itemID, 1);
}
en/create/functions/preset.txt · Last modified: 29.09.2015 20:31 by admin
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Driven by DokuWiki