Forms and loops: Can I use the same survey at multiple times with a loop?

OS Catalina 10.15.5
PsychoPy version 2020.1.2
Standard Standalone? (y/n) standard download

What are you trying to achieve?:

I would like to have participants fill out the same survey at different time points during my experiment. I loop though two different audio cues and ask questions multiple times after the audio prompt. Ideally, I’d very much like to upload one csv of questions and see the responses at different times in the data file. I am open to whatever can display my questions multiple different times.

What did you try to make it work?:
Right now I am using builder but am open to other options. My csv for the form works if it will be used once. I have tried adding it to different sections of the experiment where it would be repeated-- it results in the loop repeating incorrectly or not running at all. I have tried creating copies of the form to be read as a variable depending on the loop number as well, but the experiment will not run.

What specifically went wrong when you tried that?:
When I try it in the section that would loop once, I never make it past the Condition_Script. When I attempt it either with one form or multiple copies listed as variables I press run and it does not and returns this error message:
IndentationError: unexpected indent

Thank you for your advice!

Hi There,

You can present a form multiple times in a loop.

Here is a demo that will present a form to collect demographic data multiple times in a loop.
myForm.psyexp (19.5 KB) demographics.csv (515 Bytes)

Hope this helps,

Good morning,

Thank you for your response. When I run this, I still cannot seem to get the form to appear multiple times. I have attempted to use a condition key to stop the form, but it does not seem to work. I can only leave the form by inserting an additional keyboard input to prompt the end of the routine-- in both cases, I cannot seem to get multiple runs of the form. Is this a mac issue?

with keyboard input: (I’m not sure how to have the option to submit the questions!)

Hi There,

I don’t think it is a mac issue as I am using v 2020.2.3 on mac. For me the flow of the demo looks like this (although this is in a different colour theme!)

Here “demog” if the routine containing the form and it presents 4 times when the experiment is run (twice in the loop and the loop repeats twice) when I view the .csv file output I can see that the form was repeated multiple times by viewing the nReps column.

In your example (image 1) it might not “look” as though the form is repeated because there is nothing else in the “nquestions” loop. Try adding an additional component in the nquestions loop and it should repeat the form repeatedly.

Let me know how you get on :slight_smile:

Ah ok, thank you!! Adding the trial between demogs helped! Is there a way to clear the demog form? When it opens a second time, the responses from the previous entry are still present! Does it appear that way for you?

Ah yes, I can see that is is not so intuitive to clear the form responses - how many times do you need to recheck the participants responses throughout the study? if it is only a few it might be easiest (for now) to create a new form component (but feed in the same .csv file)?

I have a simmilar issue, with one complication. In my experiment I want to show several images, one at a time, in a random order, each followed by a form related to it. I made a loop with an Image, a Form, and a Text input to exit the Form. The problem is that each time the Form is shown, it has the answers of its previous appearance, and I don’t think the answers are related to each image.
Thanks a lot for any help!!

it would be really nice if you could tell us a way to clear the form responses

Clearing form responses is not easily implementable at the moment. If possible use separate form components.

Hello there!
I was wondering whether there are any updates on this topic - did anyone here find a more elegant solution than using x seperate form components or is there a way now to “clear” the form responses in a more elegant way that I don’t know of yet? Any help on this topic is much appreciated, as I want to avoid creating 26 forms that are basically the same…
Thank you and best regards!

Hi There,

Sorry this is still an issue that we hope to be fixed in the near future - for now I would suggest still utilising seperate forms - sorry about that!

1 Like

Hello There,

If I got this thread right it seems me to be possible to loop over forms.
Please correct me, if I am wrong, but in this case it should be possible to insert a variable from the trials loop - let’s say $questionnaire_file, or something similar - into the “Items”-cell in the form Properties, right, or how do you loop the different forms?

Still, when I try to do this, I cannot even start the experiment and I get feed back that the $questionnaire_file is not defined.

I am somewhat confused and though I even would be happy to create the same form several times, this does not work for me. What am I doing wrong?

Thank you! :slight_smile:

You can use the same Form :form: multiple times in a loop, as in the example Becca shared, but you can’t change the items each iteration - that parameter is used for creating the Form object and isn’t (currently) settable on each repeat, as a Form :form: with different items will essentially be a totally different form.

This means that if you set it as a code value (with a $), that value will be used at the beginning of the experiment - before the loop has started, hence the “not defined” error. In this instance I reckon it’s best to just make each form as a different component - you could use branching (as in the branchedExperiment demo under Demos → Design Templates) to choose which one to display on each iteration of the loop to save you having to duplicate all the other routines too.

1 Like

Thank you for your very fast reply!

If I get it right I have to go for your second suggestion, because even though I do not want to change the form’s items in each iteration - the questionnaire will stay the same in each block -, I want to investigate the response changes in reaction to the stimuli that will be changed over the blocks. Also, trying to insert the questionnaire at the end of the blocks only led to the case that it was showed at the end of the first block but did not show up at the end of the other blocks.

So in order to do what I want to do, I will have to go with your second suggestion, right? :slight_smile:
Or is there another possibilty to call the same questionnaire after each block without overwriting the responses?


If the items remain the same, then what is questionnaire_files? Is it a value which remains unchanged throughout the experiment?

Hey Todd,

First of all thank you for help! :slight_smile:
I am convinced it helps me thinking.

In the version I just showed there was no $questionnaire_files variable - this was my first try to implement my idea. The questionnaire file was directly loaded into the “items” of form compoonent via file. Unfortunately, it was only showed once then after the first block and was leaved out after the other blocks.

Tomko :slight_smile:

I’m still unclear as to your experiment design, could you share the .psyexp file and any relevant tables?

Hey Tedd,

Of course I can.
Please be not irritated by the stimuli and items! It is just a mockup version, yet, which will be replaced by the real stimuli as soon as I know it works.

mockup.psyexp (27.7 KB)
questionnaire_form_1.xlsx (13.4 KB)
conditions.xlsx (8.7 KB)
stimAlarm01.xlsx (8.8 KB)
stimAlarm02.xlsx (8.8 KB)

Thanks! :slight_smile:

Ahh, I see the problem: You’ve set the Form :form: to end when complete, but it’s already complete from the last iteration. You can fix this by putting the following code in a Code :code: component, in the same routine as questionnaire_form, in the Begin Routine tab:

for item in questionnaire_form.items:
    item['responseCtrl'].rating = None
1 Like

Thank you very much! :slight_smile: I will try this.