What cat spirit are you?
CODE FOLLOWS
<?php
include('../includes/header.php');
// code
$step = isset($_POST['step']) ? $_POST['step'] : 0;
if ($step == 0) // first time into this form
{
?>
<h1>What cat spirit are you?</h1>
<form method="POST">
<fieldset>
<legend><h3>1. What time do you prefer?</h3></legend>
<label><input type="radio" name="q1" value="1"> Morning</label><br>
<label><input type="radio" name="q1" value="2"> Midnight</label><br>
<label><input type="radio" name="q1" value="3"> Afternoon</label><br>
<label><input type="radio" name="q1" value="4"> Noon</label><br>
<br>
</fieldset>
<fieldset>
<legend><h3>2. What do you like best?</h3></legend>
<label><input type="radio" name="q2" value="1"> Ice Cream</label><br>
<label><input type="radio" name="q2" value="2"> Burgers</label><br>
<label><input type="radio" name="q2" value="3"> Tacos</label><br>
<label><input type="radio" name="q2" value="4"> Hotdogs</label><br>
<br>
</fieldset>
<fieldset>
<legend><h3>3. Favorite activity?</h3></legend>
<label><input type="radio" name="q3" value="1"> Nap</label><br>
<label><input type="radio" name="q3" value="2"> Walk</label><br>
<label><input type="radio" name="q3" value="3"> Exercise</label><br>
<label><input type="radio" name="q3" value="4"> Read</label><br>
<br>
</fieldset>
<br><br>
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
<br><br>
</form>
<?php
}
else // else show what the form gathered
{
$q1 = isset($_POST['q1']) ? $_POST['q1'] : 0;
$q2 = isset($_POST['q2']) ? $_POST['q2'] : 0;
$q3 = isset($_POST['q3']) ? $_POST['q3'] : 0;
$answers = [$q1, $q2, $q3];
$score = 0;
foreach ($answers as $a) {
$score += $a;
}
if ($score == 0) {
$result = "Head Empty Cat";
$gif = "../images/head-empty-cat.gif";
}
elseif ($score <= 4) {
$result = "Leaf Cat";
$gif = "../images/cat-leaf.gif";
}
elseif ($score <= 6) {
$result = "Egg Cat";
$gif = "../images/eggcar.gif";
}
elseif ($score <= 8) {
$result = "Smiling Dog";
$gif = "../images/dog-smiling.gif";
}
elseif ($score <= 10) {
$result = "Professional Cat";
$gif = "../images/professional_cat.gif";
}
elseif ($score <= 12) {
$result = "Turtle";
$gif = "../images/turtle.gif";
}
echo "<h2>Congratulations!</h2>";
echo "<h3>You got: $result</h3>";
echo "<img src='$gif' width='250'>";
?>
<form action="cat.php" method="POST">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
<br><br>
</form>
<?php
}
include('../includes/footer.php');
?>