next up previous contents index
Next: Java and Java Script Up: Examples Previous: A PHP-script that shows   Contents   Index


Passing more information with HIDDEN fields (PHP)

The following is an extension of the above example. In addition to the completion of the two poems, participants are further asked to fill in their gender. This variable is then passed on from form to form through hidden fields.

<HTML>
<BODY>
<?
echo "<FORM METHOD=POST ACTION=$SCRIPT_NAME>";

function ask_gender () {
    echo "Please check your gender:<P>
    <INPUT TYPE=RADIO NAME=GENDER VALUE=M> M<BR>
    <INPUT TYPE=RADIO NAME=GENDER VALUE=F> F<BR>
    <INPUT TYPE=RADIO NAME=GENDER VALUE=X> unknown<BR>
    <INPUT TYPE=HIDDEN NAME=TODO VALUE=1>
    <INPUT TYPE=SUBMIT VALUE=Continue>";
}

function store ($daten) {
   $filedescriptor = 
       fopen ("verse.txt","a");
   flock ($filedescriptor,2);              
   fwrite($filedescriptor,"$daten\n");       
   fclose ($filedescriptor);
}


function show_verse ($vers,$todo) {
   global $GENDER;
   switch ($GENDER) {
        case "F": echo "You are a woman";break;
        case "M": echo "You are a man";break;
        default: echo "You do not seem to know...";break;
    }
    
   echo "<h4>Please complete the following poem:</h4>
       $vers...<BR>
   <INPUT TYPE=TEXT NAME=VERSE SIZE=30>
   <INPUT TYPE=HIDDEN NAME=TODO VALUE=\"$todo\">
   <INPUT TYPE=HIDDEN NAME=GENDER VALUE=\"$GENDER\">
   <INPUT TYPE=SUBMIT VALUE=\"Fertig\">";
}

if ($VERSE) store ($VERSE);

switch ($TODO) {
    case "1":
        show_verse ("To run o'er better waters hoists its sail<BR>
  The little vessel of my genius now,<BR>
  That leaves behind itself a sea so cruel;", "2");
        break;
    case "2":
        show_verse ("And of that second kingdom will I sing<BR>
  Wherein the human spirit doth purge itself,<BR>
  And to ascend to heaven becometh worthy.", "3");
        break;
    case "3":
        echo "Thank you for participating<BR>\n";
        break;
    default:
        ask_gender ();
    }
?>
</FORM>
</body>
</html>


next up previous contents index
Next: Java and Java Script Up: Examples Previous: A PHP-script that shows   Contents   Index
Oliver Kirchkamp