2. Quiz

2. Quiz to check understanding

Ensuring that participants understand the instructions is essential in many behavioural experiments. It is therefore often useful to add a quiz whose questions have to be answered correctly before a participant can proceed. Open the file quiz.php in your editor. You will see the same basic setup as the instructions file: first some lines of PHP code, followed by HTML.

This time, let us start with the HTML code. Basically, this page is an HTML form, in which the participant will have to enter his answers to the control questions. The specification of the form quizForm (line 78) contains an attribute onsubmit=return confirm_form(this). Once the participant clicks the button to submit the form, the JavaScript function confirm_form (lines 53-72) will be executed to check if the answers to the control questions are correct (JavaScript can be used to program the behaviour of webpages; for more info, click here). The function confirm_form looks for the HTML form quizForm, and reads the values in its variables q1 and q2 (lines 56 and 65). These values correspond to the input fields in the form (lines 85 and 90). The entered values are compared to the correct answers.

Note that the correct answer for question 2 depends on the multiplication factor in the public goods game, as defined by the experimenter. The command on line 64 includes a PHP script to read the parameter multiplier from the server to calculate the correct answer. In case one of the two answers is wrong, the function confirm_form returns false, the form is not submitted, and the participant cannot proceed.

If both answers to the control questions are correct, we have verified that the participant has understood the instructions. The form is submitted to the server. Now scroll your way up to the PHP part of this code. In lines 25-30, we specify what happens in case of successful submission of the form: we tell the server that this participant has finished the quiz (quizOK in line 27), and let the participant proceed to a page called lobby.php; line 28 and 29.

We will get to the waiting pages later. Let us first have a look at the decision page.