Another HTML File

"simpleform2.html"

<html>
<head>
    <title>Test Program: Send Form to PHP script</title>
</head>

<Body>

<form method='post' action='simpleformproc2.php'>
     Enter your name:<br>
     <input type='text' name='yourname'>
     <P>

     <input type="radio" name="sex" value="male" checked>Male<br>
     <input type="radio" name="sex" value="female">Female<br>
     <P>

     <input type="checkbox" name="likes[]" value="movies">Movies<br>
     <input type="checkbox" name="likes[]" value="books">Books<br>
     <input type="checkbox" name="likes[]" value="hiking">Hiking<br>
     <input type="checkbox" name="likes[]" value="sleeping" checked="checked">Sleeping<br>
     <P>

     <input type='submit' value="submit">
</form>

</Body>
</html>


A more complex PHP script

"simpleformproc2.php"
<!-- Demo script to process a simple form -->
<html>
<head>
     <title>Processor of simpleform2.html</title>
</head>

<body>
<center>
<?php


/***** say hello to him or her *****/
$title = ($_POST['sex'] == "male") ? "Mr." : "Mrs.";
echo "Hello $title ";

$name = $_POST['yourname'];
if (strlen($name) == 0)              // Did they enter a name?
     echo "whoever you are.";
else
     echo $name;

echo "<P>";


/**** What likes do we share *****/
if ( isset ( $_POST['likes'] ) )
    $likes = $_POST['likes'];        // retrieve array of likes from POST array
else
    $likes = null;

if (count($likes) == 0)
     echo "Sorry you don't like anything that I like.";

elseif (count($likes) == 1)
     echo "I like $likes[0] too.";

elseif (count($likes) == 4)
     echo "Wow! You like everything I like.";

else
   {
     echo "I also like ";
     $longstring = implode (", ", $likes);                         //build a long comma delim string
     $loc = strrpos ($longstring, ",");                              //find last comma
     $longstring=substr_replace($longstring," and",$loc,1);   // replace last comma with "and"
     echo $longstring;
     echo ".<P>";
   }


/***** debugging code to show all POST data *****/
echo "<P> <hr> <P>";
print_r($_POST);
echo "<hr> <P>";

?>

</body>
</html>