", print_r($_POST, true), "
"; // show errors ini_set('display_errors',1); /* Read in CGI Data Let's begin by reading in all the data that are relevant to our project. Note: The simplist way to do this is to read in, quite literally, EVERYTHING that we will need at ANY point during the project--whether it exists at this pass or not. */ // Data the user gives us $v01 = $_POST['v01']; $v02 = $_POST['v02']; $v03 = $_POST['v03']; $v04 = $_POST['v04']; $v05 = $_POST['v05']; $myname = $_POST['myname']; // Some data that we create and want to use and read on each pass $pass = $_POST['pass']; // Where to start? // If pass is empty, assume it is the person's first time here // and set pass to 1 to start. if(empty($pass)){ $pass = 1; } /* If pass == 1, then that signals to us that the user should receive whatever information we want to display on the FIRST VISIT (e.g., consent information, overview of study). Note. At the end of this PASS, we manually set the value of $pass to 2 in a hidden tag. This will queue the script to do something different next time it loads. */ // Pass = 1 if($pass == 1){ print "

Hello! Welcome to my website.

Please tell me your name.

name

"; } // End pass == 1 /* If pass>= 1 AND <= 7, then let's present the trials or items. Each time through, we increment pass by a value of 1. Thus, we end the "loop" once pass is 8 or higher. */ if($pass >= 2 AND $pass <= 7){ print "
"; /* Pass ALL information forward as hidden tags Important notes: - We do this WITHIN the
tags because we are using hidden tags to insert information/data within the magical input area of the page. - We do this BEFORE collecting information within this pass step. Why? This allows us to pass forward the value of, say, $v01 as a hidden variable without overwriting the value that the user just entered. If we pass as hidden v01=$v01 and then present item v01, then user-supplied value will (properly) overwrite the empty value that we passed in the hidden tag. If, instead, we were to collect v01 via the input field and then pass as hidden v01=$v01, we would be overwritting the user-supplied value with the nothingness that had originally be passed forward in the CGI data packet. Confusing? Ask me more in class. Bottom line: Do this at the START of the FORM rather than near the END where the submit button is. */ /* Create HIDDEN tags for ALL information. Do this at start of FORM. */ print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; /* Allow the item/trial to increment with each submit button */ if($pass == 2){ print "

Hi, $myname. For this next part of the survey we would like for you to answer a few questions about your current mood. Please place a checkmark next to each item that describes your current mood.

"; } if($pass == 3){ print "

tired

"; } if($pass == 4){ print "

hungry

"; } if($pass == 5){ print "

anxious

"; } if($pass == 6){ print "

sad

"; } if($pass == 7){ print "

excited

"; } print ""; /* Here we are using a new trick. Specifically, instead of manually setting pass to the appropriate value (e.g., $pass=4;), we are going to increment it by 1. Thus, as the person moves from one item to the next, we increment pass by 1. This allows us to ensure that the person is getting the appropriate item at each step along the way. Notice also that, instead of writing $pass = $pass + 1, I wrote $nextpass = $pass + 1. I did this to ensure that I was not overwriting the current value of pass within the script. There are no ill consequenes of doing so here, but there are other situations in which it could matter. Thus, this is a generic solution to a problem that doesn't exist and, now, will never exist. */ $nextpass = $pass + 1; print ""; print " "; } // End if($pass >= 2 OR $pass <= 7) // Pass = 8 /* We're at the end. Yay. */ if($pass == 8){ if($v01 == 1){ $message = "

Hope you're feeling more lively later today! Coffee helps.

"; } print "

Thanks for your time, $myname. $message

"; } // End pass == 8 ?>