0 votes
in SoSci Survey (English) by s266003 (120 points)
edited by SoSci Survey

Hello! I have a survey where i use the looppage function to display texts drawn from a random generator and some questions below. But for each time it is looped to a new page, the questions QE01 and QE02 are overwritten in the data. How can i change this? i would like to save the answers for every time they answer the question. My code look like this:

if (!isset($draws)) {
  $draws = array_merge(
    array_values(valueList('RG01', NULL, 'label')),
    array_values(valueList('RG02', NULL,'label')),
  );
  shuffle($draws);
  registerVariable($draws);
}

$i = loopPage(count($draws));
// Show the text
$textID = $draws[$i];
$data = dbGet($textID);
html('<strong>'.$data[0].'</strong>');
html('<p>'.$data[1].'</p>');
// Store the text ID
put(id('DA01', $i+1), $textID);

(i here dragged the 2 question elements from the elements menu)

1 Answer

0 votes
by SoSci Survey (306k points)

How can i do such that for each page shown the type and likert scale questions become 'blank' when you click next page?

That's an important one, because if it does not, then you show the same question over and over again, and respondents will delete their previous questions. Literally.

So, if you have 3 copies of the questions, let's say:

$questions = [
  1 => ['QE01', 'QE02'],
  2 => ['QE03', 'QE04'],
  3 => ['QE05', 'QE06']
];

the show another pair like this:

$i = loopPage(count($draws));
...
show($questions[$i][0]);
show($questions[$i][1]);

Is there anywhere i can see the file output of a finished response of the questionnaire?

Look in collected data -> view data

by s266003 (120 points)
I have now made duplicates of QE01 and QU02, ranging from QE01 to QE16 (2 questions pr. page), i tried your code, and my php code look like this:
if (!isset($draws)) {
  $draws = array_merge(
    array_values(valueList('RG01', NULL, 'label')),
    array_values(valueList('RG02', NULL,'label')),
  );
  shuffle($draws);
  registerVariable($draws);
}

$questions = [
  1 => ['QE01', 'QE02'],
  2 => ['QE03', 'QE04'],
  3 => ['QE05', 'QE06'],
  4 => ['QE07', 'QE08'],
  5 => ['QE09', 'QE10'],
  6 => ['QE11', 'QE12'],
  7 => ['QE13', 'QE14'],
  8 => ['QE15', 'QE16'],
];

$i = loopPage(count($draws));
// Show the text
$textID = $draws[$i];
$data = dbGet($textID);
html('<strong>'.$data[0].'</strong>');
html('<p>'.$data[1].'</p>');
//show($questions[$i][0]);
show($questions[$i][1]);
show($questions[$i][2]);
show($questions[$i][3]);
show($questions[$i][4]);
show($questions[$i][5]);
show($questions[$i][6]);
show($questions[$i][7]);
show($questions[$i][8]);
// Store the text ID
put(id('DA01', $i+1), $textID);


However, something is not working as i get errors like:

Questionnaire Error: Undefined array key 0
line: 30

PHP code

027 html('<strong>'.$data[0].'</strong>');
028 html('<p>'.$data[1].'</p>');
029  
030 show($questions[$i][1]);
031 show($questions[$i][2]);
032 show($questions[$i][3]);
033 show($questions[$i][4]);
Questionnaire Error: Trying to access array offset on value of type null
line: 30

PHP code

027 html('<strong>'.$data[0].'</strong>');
028 html('<p>'.$data[1].'</p>');
029  
030 show($questions[$i][1]);
031 show($questions[$i][2]);
032 show($questions[$i][3]);
033 show($questions[$i][4]);

What did i do wrong here?
by SoSci Survey (306k points)
The error occurs because $i starts at 0, but following my recommendation, you started with index 1 => in the array. I assume it's better to start with 0, i.e., skip manul definition of indices:

$questions = [
  ['QE01', 'QE02'],
  ['QE03', 'QE04'],
  ['QE05', 'QE06'],
  ['QE07', 'QE08'],
  ['QE09', 'QE10'],
  ['QE11', 'QE12'],
  ['QE13', 'QE14'],
  ['QE15', 'QE16'],
];

But there's another important thing. Remove that section here:

//show($questions[$i][0]);
show($questions[$i][1]);
show($questions[$i][2]);
show($questions[$i][3]);
show($questions[$i][4]);
show($questions[$i][5]);
show($questions[$i][6]);
show($questions[$i][7]);
show($questions[$i][8]);

And instead use my code:

show($questions[$i][0]);
show($questions[$i][1]);

No more. For each "line" in the $questions array you have two entries, for example:

['QE01', 'QE02']

That means if written in the long form:

[0 => 'QE01', 1 => 'QE02']

So, you only have 0 and 1.
by s266003 (120 points)
Thank you so much!

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...