<?php
include('../includes/header.php');
// code
error_reporting(E_ALL); // set error reporting to all
echo('<h1>Story Time</h1>');
echo('<h2>Insert Words To Complete The Story!</h2>');
// Note the variables being passed via the GET ternary operators.
$step = isset($_GET['step']) ? $_GET['step'] : 0;
$name = isset($_GET['name']) ? $_GET['name'] : '';
$verb = isset($_GET['verb']) ? $_GET['verb'] : '';
$adjective = isset($_GET['adjective']) ? $_GET['adjective'] : '';
$verbing = isset($_GET['verbing']) ? $_GET['verbing'] : '';
// filter all input taken from the Browser
$step = htmlentities($step);
$name = htmlentities($name);
$verb = htmlentities($verb);
$adjective = htmlentities($adjective);
$verbing = htmlentities($verbing);
if ($step == 0) // first time into this form
{
?>
<form action="../examples/my-strings-example.php" method="GET" class="pad">
<label for="name">Woman's Name</label>
<input type="text" size="36" id="name" name="name" value="">
<br><br>
<label for="verb">Present-Tense Verb</label>
<input type="text" size="36" id="verb" name="verb" value="">
<br><br>
<label for="adjective">Adjective</label>
<input type="text" size="36" id="adjective" name="adjective" value="">
<br><br>
<label for="verbing">Verb(ing)</label>
<input type="text" size="36" id="verbing" name="verbing" value="">
<input type="hidden" name="step" value="1">
<input type="submit" name="submit" value="Submit">
<br><br>
</form>
<?php
} else // story
{
$inputs = $name . $verb . $adjective . $verbing;
$count = strlen($inputs);
$story = "Once upon a time, there was a princess named $name.
<br><br>
She loved to $verb in her free time.
<br><br>
She was a very $adjective princess.
<br><br>
She saved the kingdom by $verbing.
<br><br>";
echo($story);
}
// provide a form to try again
if (!$step == 0){
?>
<form action="../examples/my-strings-example.php" method="GET">
<input type="hidden" name="step" value="0">
<input type="submit" name="submit" value="Try Again">
</form>
<?php
}
include('../includes/footer.php');
?>