All pastes #402297 Raw Edit

Stuff

public text v1 · immutable
·published 2007-03-19 20:47 UTC
rendered paste body
<html>
<head>
</head>
<body>
  <?php
	$size = "3";
	$submit = isset($_POST['command']);
	$step = $_POST['step'];
	$selected = false;
	$sum = 0;

	echo '<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">';

	if($step == 1) {
		echo '<input type="hidden" name="step" value="1" />
  		Size: <input type="text" name="size" value="'.$size.'" size="6" maxlength="40"/>&nbsp;
  		<input type="submit" name="command" value="go"/><br />';
	}

	if($step == 2) {
		echo '<input type="hidden" name="step" value="2" />
	      	echo '<input type="hidden" name="size" value="3" />';
		
		echo '<option value="1"> 1 </option>';
		
		for($i=0; i < size; ++$i) {
			echo '<select name="v0">';
			echo '<option value="0">unset</option>';
			for ($j=0; $j < 20; ++$j) {
				echo '<option value="'.$j.'">'.$j.'</option>';
			}
			echo '</select>';
		}
		echo '<input type="submit" name="command" value="go"/><br />';
	}
		

	if(submit) {
		if($step == 1) {
			$size = $_POST['size'];
		
			if($size == "" || !ctype_digit($size) || $size > 12 || $size < 1) {
				step = 1;
				print "size must be an integer between 1 and 12 (inclusive)"; 
			}

			else {
				$step = 2;
			}
		}
		
		if($step == 2) {
			$selected = isset($_POST['v0']);
			for($i=0; i < size; ++$i) {
				echo '<select name="v0">';
				echo '<option value="0">unset</option>';
				for ($j=0; $j < 20; ++$j) {
					if($selected) {	
						echo '<option value="'.$j.'">'.$j.'</option>';
						$sum = $sum + $j;	
					}
					else {
						print "you must select values for all ".$size."variables.";
					}
					
				}
				echo '</select>';
				$step = 3;
			}
			
			
		}

		if($step == 3) {
			echo '<h1>And the answer is... '.$sum.'</h1>';		
		}

	}
  	
	echo '</form>';	
	
  ?>
</body>
</html>