tag in each pass. Important note: We have to attend carefully to data that are USER created vs. PROGRAMMER created. Reading in CGI data that comes from the user's input is easy: We simply use the $_POST global to extract the information from the data packed and pass it along in a hidden tag. If the information is there, we're done. If it isn't there, no harm; no foul. With PROGRAMMER created data (e.g., things, like pass, that are hidden), however, we have to be sure that we manually pass it along the first time it is created. We can still include such variables in our passhidden() function, but we must make sure we manually pass them forward as hidden tags the first time they come into existence. Until they are available to the CGI data packet, the function as written below will not be able to operate upon them. ------------------------------------------------------------------------------------ */ function passhidden(){ // hidden VARIABLES print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; print " \n"; // hidden ARRAYS // Note: We have to use isset to see if the array exists otherwise the foreach loop // will generate an error. if(isset($_POST['item_index']) | $isset){ foreach ($_POST['item_index'] as $key => $value){ echo ' '; print " \n"; } } } /* Here are some arrays we could, theoretically, want access to at any stage of the game. Thus, let's initialize them here and do so fresh on each pass rather than passing them forward as hidden tags. (In general, if there is no need to pass data via hidden tags, then don't do it.) */ $item_content = array("tired","hungry","anxious","sad","excited"); // The content/items to be presented $item_names = array("v01","v02","v03","v04","v05"); // The variable names that will be associated with each item $number_of_items = count($item_names); // How many items/trials are there? $max_index = $number_of_items - 1; // Let's take 1 minus the above /* 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). */ // Pass = 1 if($pass == 1){ /* In addition to presenting a greeting on the first page(pass), we are also going to decide at this moment the random order in which the stimuli/items will be presented. We will do so by - creating an array that contains an index for each item (i.e., its place in the array file drawer). - shuffling/randomizing the order of that array - using that shuffled array to index the actual items (and their NAMEs) - Finally, we preserve that random order by passing it forward as hidden data */ $item_index = range(0,$max_index); print "The original index of items is
"; foreach ($item_index as $key => $value){ print "$key --> $value
"; } shuffle($item_index); print "The randomized index of items is
"; foreach ($item_index as $key => $value){ print "$key --> $value
"; } print "

Hello! Welcome to my website.

Please tell me your name.

"; /* Create HIDDEN tags for ALL information. Do this at start of FORM. */ passhidden(); /* ------------------------------------------------------------------------------------ Note. The first time we create item_index, we WILL need to pass it manually as a HIDDEN tag. Note: We do the same with pass below. ------------------------------------------------------------------------------------ */ foreach ($item_index as $key => $value){ echo ' '; print " \n"; } print "

name

"; print ""; // Pass this manually the first time print ""; print "
"; } // 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. */ // We're going to skip the instructions this time, so setting $pass <= 6 instead of <= 7 if($pass >= 2 AND $pass <= 6){ print "
"; /* Create HIDDEN tags for ALL information. Do this at start of FORM. */ passhidden(); print "Do you currently feel...
"; $pass_index = $pass - 2; // let's count from 0 as we move through this section $this_item_content = $item_content[$item_index[$pass_index]]; // which item to present now? $this_item_name = $item_names[$item_index[$pass_index]]; // which item name to use? print "

$this_item_content

"; 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 ""; // Pass this manually because we've modified it print "
"; } // End if($pass >= 2 OR $pass <= 6) if($pass == 7){ if($v01 == 1){ $message = "

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

"; } print "

Thanks for your time, $myname. $message

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