<HTML><BODY onload="document.MyForm.Name.focus()">
<?php

// Sticky forms.
// How to make the form remember the previous data.
/* In this example, we'll remember data entered in text fields and
in text areas, and data entered by radio buttons, check
boxes, and selection lists.
*/

$college_titles = array("Yes", "No");
$cake_titles = array("Cheesecake", "Banana Cream Pie");
$age_titles = array("18-25","26-30","31-35","36-40","41-50",">50");

$name = trim($_REQUEST['Name']);
$country = trim($_REQUEST['Country']);
$email = trim($_REQUEST['Email']);
$comments = trim(stripslashes($_REQUEST['Comments']));

$age=array();
$k = $_REQUEST['Age'];
$age[$k] = 'Selected="selected"';
// $age[$k] = 'Selected="true"';		

$college=array();
$k = $_REQUEST['College'];
$college[$k] = 'Checked="checked"';
// $college[$k] = 'Checked="true"';

$cake = array();
$k = $_REQUEST['ck'];
if ($k == 0)
	$cake[$k] = 'Checked="checked"';
$k = $_REQUEST['bcp'];
if ($k == 1)
        $cake[$k] = 'Checked="checked"';


echo <<< Begin

<TABLE WIDTH=80% ALIGN=center><TR><TD>

<fieldset>
<legend><B>
Please fill out this form and submit it.
</B></legend>

<CENTER>
<FORM NAME="MyForm" 
ACTION="{$_SERVER['PHP_SELF']}" METHOD="post">


<B>Name:</B>
<INPUT NAME="Name" SIZE=30 VALUE="$name">
<P>

<B>Country/State</B>
<INPUT NAME="Country" SIZE=30 VALUE=$country>
<P>

<!-- Note now that we have values for the options -->

<B>Age:</B>
<SELECT NAME="Age">
<OPTION value=0 $age[0]>18 - 25
<OPTION value=1 $age[1]>26 - 30
<OPTION value=2 $age[2]>31 - 35
<OPTION value=3 $age[3]>36 - 40
<OPTION value=4 $age[4]>41 - 50
<OPTION value=5 $age[5]> > 50
</SELECT>

<!--
$a = $_REQUEST('Age');
foreach ($age_titles as $k => $v) {
	echo "<OPTION VALE=\"$k$\"";
	if ($k == $a)
		echo 'Selected="selected"';
	echo ">$v</OPTION>";
}
echo "</SELECT>";
-->

<P>

<B>Email:</B>
<INPUT NAME="Email" SIZE=30 VALUE="$email">
<P>

<!-- Note now that we chanegd the values of the radio buttons -->
<B>College Student/Graduate?</B>
<INPUT NAME="College" TYPE="radio" VALUE="0" $college[0]>
<B>Yes</B>
<INPUT NAME="College" TYPE="radio" VALUE="1" $college[1]>
<B>No</B>
<P>

<!-- Note now that we have checkboxes and they have values -->

<B> 
I like</B>
<INPUT TYPE="checkbox" value="0" NAME="ck" $cake[0]> Cheesecake.
<INPUT TYPE="checkbox" value="1" NAME="bcp" $cake[1]> Banana Cream Pie.

<P>
<B>Comments:</B>
<TEXTAREA NAME="Comments" ROWS=8 COLS=30 WRAP="virtual">
$comments
</TEXTAREA>


<CENTER><INPUT TYPE="submit" VALUE="SUBMIT"></CENTER> 
<INPUT TYPE="reset" VALUE="CLEAR">


</FORM></CENTER>
</fieldset>
</TD></TR></TABLE>
Begin;

$name = trim($_REQUEST['Name']);
$country = trim($_REQUEST['Country']);
$age = $_REQUEST['Age'];
$email = trim($_REQUEST['Email']);
$college = $_REQUEST['College'];
$comments = trim(stripslashes($_REQUEST['Comments']));
$ck = $_REQUEST['ck'];
$bcp = $_REQUEST['bcp'];

echo <<< Begin

You've entered:<P>
Name: "$name"<P>
Country/State: $country<P>
Age: $age_titles[$age]<P>
Email: $email<P>
College? $college_titles[$college]<P>
I like $cake_titles[$ck] $cake_titles[$bcp]<P>
Comments: <PRE>$comments</PRE><P>
</BODY></HTML>
Begin;
	
